【发布时间】:2013-10-06 04:34:17
【问题描述】:
考虑这段代码:
$.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 不允许 访问控制允许标头。 jquery-1.9.1.js:8526 XMLHttpRequest 无法加载 http://x.com/AnnouncementCategory/Save。要求 头字段 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 在 post 中也使用 ajax。 **我知道我的错误是什么,只想知道:** $.ajax with type: post 和 jquery post 有什么区别?
【问题讨论】:
-
可能什么都没有,但这是
$.post中的额外空间吗?就在http之前。
标签: javascript jquery ajax