how to send ajax put request from jQuery
I want to write back to my google spreadsheet after authorizing user. Authorizing is complete. But, to write back to spreadsheet, I have send PUT request as stated here. It is from iGoogle Gadget.
My XML element is :
var cellUrl = "https://spreadsheets.google.com/feeds/cells/" + key + "/od6/private/full/R2C2";
var XMLData = "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gs='http://schemas.google.com/spreadsheets/2006'>" +
"<id>" + cellUrl + "</id><link rel='edit' type='application/atom+xml' href='" + cellUrl + "'/>" +
"<gs:cell row='2' col='2' inputValue='300'/>" +
"</entry>";
I am sending AJAX request as :
$.ajax({
url: cellUrl,
type: "PUT",
contentType: 'application/atom+xml',
processData: false,
data: XMLData,
error: function(XMLHttpRequest, textStatus, errorThrown){
alert(errorThrown);
}, success: function(data, textStatus, XMLHttpRequest){
alert("Succeeded");
}
});
Still, it is not writing back and not showing any alert as w开发者_JS百科ell ! What is problem ?
Should I use POST for writing back ? How do I do that ?
I have hidden cellURL key for security. And it is similar to the key in my spreadsheet url.
my suggestion
- check 'key' resourceID should escape
- if still not working, try put everything in and add and use click event. For ajax, use iframe.
- try $.ajax({... , data:$(XMLData), ...});
Can you try something like this to see whether there is an error:
$.ajax({
url: cellUrl,
type: "PUT",
contentType: 'application/atom+xml',
processData: false,
data: XMLData
}, error: function(XMLHttpRequest, textStatus, errorThrown){
alert(errorThrown);
}, success: function(data, textStatus, XMLHttpRequest){
alert("Succeeded");
}
);
精彩评论