在Ajax调用中400次重新调用

时间:2016-04-21 07:18:35

标签: javascript jquery ajax

我的Ajax调用看起来像这样

 function Submit() {
  var objectData =
         {
              email: $("#email").val(),
             firstName: $("#firstName").val(),
             lastName: $("#lastName").val(),
             loginMode: $("#loginMode").val(),
             primaryMobile: $("#primaryMobile").val() 

        };

var objectDataString = JSON.stringify(objectData);
    console.log(objectDataString);
$.ajax({
            type: "POST",
            url: "http://localhost:8080/feasthunt/customer/saveCustomerDetails",
            contentType: "application/json; charset=utf-8",
            data: objectDataString,
            dataType: "json",
            success: function (data) {
               alert('Success');
               $objectDataString.append('<li>email: '+data.email+', firstName: '+data.firstName+', lastName: '+data.lastName+', loginMode: '+data.loginMode+', primaryMobile: '+data.primaryMobile+ '</li>');

            },
            error: function () {
             alert('Error');
            }
        });
 }

我在控制台中收到的错误如下:

POST 
XHR 
http://localhost:8080/feasthunt/customer/saveCustomerDetails [HTTP/1.1 400 Bad Request 123ms]

为什么会这样?

1 个答案:

答案 0 :(得分:0)

确保请求和响应的contentType匹配。