Consider this code:
$.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)");
}
});
With above code we can post data cross domain an everything is ok. But when i use this code:
$.post(' http://x.com/AnnouncementCategory/Save')
I get this error:
OPTIONS http://x.com/AnnouncementCategory/Save Request header field X-Requested-With is not allowed by Access-Control-Allow-Headers. jquery-1.9.1.js:8526 XMLHttpRequest cannot load http://x.com/AnnouncementCategory/Save. Request header field X-Requested-With is not allowed by Access-Control-Allow-Headers.
I see the jquery source code:
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 also use ajax in post. **I know what is my error and just want to know:**What is the difference between $.ajax with type: post and jquery post?