考虑这段代码:
$.ajax({
url: "http://x.com/api/AnnouncementCategory/Save",
type: "Post",
success: function (data) {
//Grab our data from Ground Control
alert(data);
},
error: function (event) {
//If any errors occurred - detail them here
alert("Transmission failed. (An error has occurred)");
}
});
使用上面的代码,我们可以跨域发布数据,一切正常。但是当我使用这段代码时:
$.post(' http://x.com/AnnouncementCategory/Save')
我收到此错误:
选项http://x.com/AnnouncementCategory/Save请求标头字段 X-Requested-With 不允许 Access-Control-Allow-Headers。jquery-1.9.1.js:8526 XMLHttpRequest 无法加载http://x.com/AnnouncementCategory/Save。Access-Control-Allow-Headers 不允许请求头字段 X-Requested-With。
我看到jquery源代码:
function ( url, data, callback, type ) {
// shift arguments if data argument was omitted
if ( jQuery.isFunction( data ) ) {
type = type || callback;
callback = data;
data = undefined;
}
return jQuery.ajax({
url: url,
type: method,
dataType: type,
data: data,
success: callback
});
}
Jquery 在帖子中也使用 ajax。**我知道我的错误是什么,只想知道:** $.ajax with type: post 和 jquery post 有什么区别?