我已成功使用此 URL 从 JSON 格式的 Google 表格中提取数据:
https://spreadsheets.google.com/feeds/cells/<SHEETS_ID>/1/public/full?alt=json
我现在想获取 Google Docs 文档的 JSON。这样做的网址是什么?
我知道我可以使用 GET API,但我正在尝试使用简单的 AJAX 而没有 OAuth(文件是公开的)
我试图将数据从 AJAX 发布到 Google 表单,但即使它报告成功且 statusCode 为 0,数据也从未出现在表单中:
var dat={ "entry.529474552" :"data1", "entry.1066559787": "name1"};
postToGoogle("1FAIpQLSf4w1OQGsIncaiqXlmfAl4jYSt-e4Zx3xVJa7Weob4LnQbRZQ",dat);
function postToGoogle(id, dat) {
$.ajax({
beforeSend: function (xhr) {
xhr.setRequestHeader('Access-Control-Allow-Origin', 'chrome-extension://EXTENSION_ID');
xhr.setRequestHeader('Access-Control-Allow-Methods', 'GET, POST, PUT');
},
url: "https://docs.google.com/forms/d/e/"+id+"/formResponse",
data: dat,
type: "POST",
dataType: "xml",
xhrFields: { withCredentials: true },
statusCode: {
0: function() { console.log("OK") },
200: function() { console.log("error") },
}
});
}
Run Code Online (Sandbox Code Playgroud)
它会生成 CORS 错误,但据说 POST 无论如何都应该通过。