Linked Questions

Popular Questions

AJAX call to rest service to post the data from HTML form

Asked by At
<html>

<body>
    <form method="POST">
        <label>username</lable>
            <input id="username" name="username" type="text">
            <label>emailid</lable>
                <input id="emailid" name="emailid" type="text">
                <button id="enter" type="submit">submit</button>
    </form>
    <script type="text/javascript">
        $(document).ready(function () {
            var userName = $("#username").val();
            var emailId = $("#emailid").val();
            $($enter).click(function () {
                $.ajax({
                    type: 'POST',
                    url: ".....rest service url....",
                    dataType: JSON,
                    data: {
                        "UserName": userName,
                        "EmailId": emailId
                    },
                    success: function (data) {
                        alert("success");
                    }
                    error: function (e) {
                        alert("error" + e)
                    }
                });
            });
        });
    </script>
</body>

</html>

I'm trying to post the form field in rest service which expects a JSON response. I'm getting an alert error message (object Object)

I'm not getting where the error is.

Related Questions