开发者

how to send ajax put request from jQuery

开发者 https://www.devze.com 2023-02-06 07:34 出处:网络
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.

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");
    }

);
0

精彩评论

暂无评论...
验证码 换一张
取 消