Doing an ajax get request works as expected using the following code:
$.ajax({
type: "GET",
contentType: "application/json",
url: "http://someSeceretUrl/test/document,
dataType: "jsonp",
success: function(msg) {
console.log(msg);
},
error: function(a,b,c) {
console.log(a);
console.log(b);
console.log(c);
}
});
But a PUT ajax call using the following code:
$.ajax({
type: "PUT",
contentType: "appli开发者_Python百科cation/json",
url: "http://someObscureURL/test/mrmer1",
dataType: "jsonp",
data: {"name":"mike"},
success: function(msg) {
console.log(msg);
},
error: function(a,b,c) {
console.log("XMLHttpRequest: " + a);
console.log("textStatus: " + b);
console.log("errorThrown: " + c);
}
});
results in the following console output:
XMLHttpRequest: [object XMLHttpRequest]
textStatus: null
errorThrown: [Exception... "Access to restricted URI denied" code: "1012" nsresult: "0x805303f4 (NS_ERROR_DOM_BAD_URI)" location: "http://static.kobj.net/kobj-static-20100219162227.js Line: 371"]
I am thinking that something is blocking the PUT request, but I don't know. What am I doing wrong?
Thanks!
I suppose you are hitting cross domain restrictions. I wouldn't be surprised if http://username:password@somehost
is considered as cross domain.
When I've done PUT requests in the past, I've found that not passing the contentLength header results in an exception being thrown, just a thought
精彩评论