每次调用下面的whatever
函数时,error
函数都会触发。
使用Firebug我能够确定ajax调用是将data
中的json字符串附加到url
查询字符串的末尾。像这样:
https://example.com/api/Controller/Method?callback=jQuery203016199810379339108_1481539294422& { “JSON”: “数据”}&安培; _ = 1481539294423
我打算将它发送到请求正文中。那么......如何通过请求体而不是url查询字符串发送data
?
function whatever(model, url) {
$.support.cors = true;
var data = JSON.stringify(model);
$.ajax({
type: 'POST',
url: url,
headers: {'x-whatever': 'whatever'},
crossDomain: true,
contentType: 'application/json; charset=utf-8',
dataType: "jsonp",
data: data,
success: function (msg) { },
error: function (request, status, error) {
console.log(url);
console.log(status + error);
}
});
}