开发者

how do I send 'put' request through javaScript & Ajax?

开发者 https://www.devze.com 2023-02-03 15:15 出处:网络
I have to write to my spreadsheet programatically. It allows my to write to a particular cell of the spreadsheet. My code is :

I have to write to my spreadsheet programatically. It allows my to write to a particular cell of the spreadsheet. My code is :

function update(){
                jQuery.ajax({
                    type: 'PUT',
                    contentType: "application/atom+xml",
                    url: "https://spreadsheets.google.com/feeds/cells/0Aq69FHX3TV4ndDBDVFFETUFhamc5S25rdkNoRkd4WXc/od6/private/full/R2C1",
                    dataType: "xml",
                    data: "new.xml",
                    success: function() {
                        alert('Put Success');
                    },
                    error: function(a,b,c) {
                        console.log("XMLHttpRequest: " + a);
                        console.log("textStatus: " + b);
                        console.log("errorThrown: " + c);
                        alert("XMLHttpRequest : " + a + " textStatus : " + b + " errorThrown : " + c);
                    }
                });
            }

I can write to spreadsheet using xml element only. So, I have created (new.xml):

<entry>
    <id>https://spreadsheets.google.com/feeds/cells/0Aq69FHX3TV4ndDBDVFFETUFhamc5S25rdkNoRkd4WXc/od6/private/full/R2C1</id>
    <link rel="edit" type="application/atom+xml"
    href="https://spreadsheets.google.com/feeds/cells/0Aq69FHX3TV4ndDBDVFFETUFhamc5S25rdkNoRkd4WXc/worksheetId/private/full/R2C1"/>
    <gs:cell row="2" col="1" inputValu开发者_如何转开发e="300"/>
</entry>

But, my code it is still throwing an error. I think it is related to the XML file I am writing. I think, creating new.xml is my error. Please suggest how to write back? How do I create an xml element ?

For referece : Update Cells

Output : a : [object Object]

b : undefined

c :


Due to same origin policy restriction you cannot send AJAX requests cross domain. Here you are trying to send an AJAX request to https://spreadsheets.google.com and unless your site is hosted on https://google.com this won't work. To try to workaround this restriction you could write a server script on your server which will serve as a bridge between your domain and google.com. Then you could send the AJAX request to your script which will delegate.

0

精彩评论

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