最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - google spreadsheets - ajax call (get and post) - Stack Overflow

programmeradmin7浏览0评论

what I need to do is read the content of a "public" google spreadsheet (by public I mean that I saved the sheet clicking on "File > Publish to the web", so it's accessible without the need to be logged in into a google account), and, why not, write something into it too.

googlin' around, I found that I can access the sheet and get the xml equivalent of the sheet content with something like

/<sheetCode>/od6/public/values

It works great if I load that url into a browser. But I need to find a "javascript-way" to get and handle the returned value, ie the xml (or json, but xml would be preferable).

I tried to use an ajax call, but I think there's something messy with the protocol.. I can't get the server response correctly.

$.ajax({
    type: "GET",
    url: "/<sheetCode>/od6/public/values",
    success: function(data){alert("yeah");},
    error: function(){alert("fail..");},
    dataType:"xml",
});

I also tried to get the json instead of xml, adding "?alt=json" to the url and changing the datatype, but I still have the problem..

Any idea / suggestion?

Thanks in advance, best regards

what I need to do is read the content of a "public" google spreadsheet (by public I mean that I saved the sheet clicking on "File > Publish to the web", so it's accessible without the need to be logged in into a google account), and, why not, write something into it too.

googlin' around, I found that I can access the sheet and get the xml equivalent of the sheet content with something like

https://spreadsheets.google./feeds/list/<sheetCode>/od6/public/values

It works great if I load that url into a browser. But I need to find a "javascript-way" to get and handle the returned value, ie the xml (or json, but xml would be preferable).

I tried to use an ajax call, but I think there's something messy with the protocol.. I can't get the server response correctly.

$.ajax({
    type: "GET",
    url: "https://spreadsheets.google./feeds/list/<sheetCode>/od6/public/values",
    success: function(data){alert("yeah");},
    error: function(){alert("fail..");},
    dataType:"xml",
});

I also tried to get the json instead of xml, adding "?alt=json" to the url and changing the datatype, but I still have the problem..

Any idea / suggestion?

Thanks in advance, best regards

Share Improve this question edited Dec 16, 2013 at 15:31 Kara 6,22616 gold badges53 silver badges58 bronze badges asked Nov 20, 2012 at 16:56 BeNdErRBeNdErR 17.9k21 gold badges77 silver badges106 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

You need to request with a JSONP call and you need to specifiy a callback - method. This can be done in jQuery using:

var url = 'https://spreadsheets.google./feeds/list/<CODE>/od6/public/values?alt=json-in-script&callback=?';
jQuery.getJSON(url).success(function(data) {
    console.log(data); 
}).error(function(message) {
    console.error('error' + message); 
}).plete(function() {
    console.log('pleted!'); 
});

Documentation and samples for google spreedsheets .

发布评论

评论列表(0)

  1. 暂无评论