我正在尝试发送失败的ajax调用。我真的不知道为什么会这样。
有人可以看看我的代码。
调用甚至没有达到控制器代码(在我看来),尽管在fireBug中我可以看到有效负载正在被正确转换。
jquery的
function userAdd(){
var array2=new Array();
var array1=new Array();
var value2=$('input:checkbox.value2').each(function () {
if(this.checked){
array2.push($(this).attr('itemLabel'));
}
});
var value1=$('input:checkbox.value1').each(function () {
if(this.checked)
array1.push( $(this).attr('itemLabel'));
});
var report = ({
user:user,
address:$("#address").val(),
regimesRemove:array2,
regimesReport:array1
});
jQuery.ajax( {
async : false,
cache : false,
url : "/myapp/user/addUser",
type : 'POST',
contentType: "application/json; charset=utf-8",
dataType : 'json',
data:JSON.stringify(report),
success : function(data) {
if(data.errorMessage == undefined){
alert(data.errorMessage);
window.location.reload();
}else if(data.errorMessage !=''){
alert(data.errorMessage);
window.location.href="/myapp/user";
else
window.location.href="/myapp/user";
},
complete : function(request, status) {
if (status == undefined || status == "error" || status == "parsererror") {
alert("Error with status: "+status);
window.location.href="/myapp/user/";
} else if (status != 'success'){
alert("error with status: "+status);
alert('error in searching Invalid or submitted records: '+status);
}
}
});
}
爪哇
@RequestMapping(value="/addUser",method=RequestMethod.POST)
public @ResponseBody Report updateRulesForRequest(Model model, HttpServletRequest request,@RequestBody Report report){
}
登录
Request URL:http://localhost:8080/myapp/user/addUser
Request Method:POST
Status Code:400 Bad Request
Response Headers
view source
Cache-Control:must-revalidate,no-cache,no-store
Content-Length:1417
Content-Type:text/html;charset=ISO-8859-1
Server:Jetty(7.0.2.v20100331)
Request Headers
view source
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:335
Content-Type:application/json; charset=UTF-8
Cookie:timezoneOffset=330; timezoneOffset=330; JSESSIONID=16ukve3dwiqt6
Host:localhost:8080
Origin:http://localhost:8080
Referer:http://localhost:8080/myapp/selectUser/getUser?Id=C9067134CA9711E56095E83935B46D68
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36
X-Requested-With:XMLHttpRequest