i am making a ajax request to some url. but each time i am getting an error as status.
$.ajax({
url: "http://api.jquery.com/jQuery.ajax/",
开发者_如何学编程 type: 'GET',
complete: function(jqXHR,textStatus) {
alert(textStatus);
}
})
each time i get "error" in textStatus. what m i doing wrong.
EDIT:
ckeck it http://jsfiddle.net/bhXbh/54/
You're trying to make a cross domain ajax call, which is forbidden by the browser's Same Origin Policy.
Assuming your remote url allows for JSONP requests, and assuming you're using JQuery > 1.5, you can simply add crossDomain:true
to your $.ajax()
params.
You can have a look at the following (ref : http://api.jquery.com/jQuery.ajax/)
xhrFields(added 1.5.1)Map
A map of fieldName-fieldValue pairs to set on the native XHR object. For example, you can use it to set withCredentials to true for cross-domain requests if needed.
$.ajax({
url: 'a_cross_domain_url',
xhrFields: {
withCredentials: true
}
});
crossDomain(added 1.5)
Default: false for same-domain requests, true for cross-domain requests
If you wish to force a crossDomain request (such as JSONP) on the same domain, set the value of crossDomain to true. This allows, for example, server-side redirection to another domain
精彩评论