title: AJAX call to rest service to post the data from HTML form
body: <pre><code>&lt;html&gt;
  
  &lt;body&gt;
      &lt;form method="POST"&gt;
          &lt;label&gt;username&lt;/lable&gt;
              &lt;input id="username" name="username" type="text"&gt;
              &lt;label&gt;emailid&lt;/lable&gt;
                  &lt;input id="emailid" name="emailid" type="text"&gt;
                  &lt;button id="enter" type="submit"&gt;submit&lt;/button&gt;
      &lt;/form&gt;
      &lt;script type="text/javascript"&gt;
          $(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)
                      }
                  });
              });
          });
      &lt;/script&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>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)</p>
  
  <p>I'm not getting where the error is.</p>