[英]Google Apps Script (GAS) - Create ContentService API to serve JSON data from Google Drive
仍在努力弄清楚在Google IO 2012上推出的所有新內容。關於GAS和ContentService,您可以創建一個API來為您的內容提供服務(來自Google雲端硬盤)。 一個簡單的例子是這樣的:
var jsonData = {
"firstName": "John",
"lastName": "Smith",
"age": 25,
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": "10021"
},
"phoneNumber": [
{
"type": "home",
"number": "212 555-1234"
},
{
"type": "fax",
"number": "646 555-4567"
}
]
}
function doGet(e) {
var output = ContentService.createTextOutput();
output.setMimeType(ContentService.MimeType.JSON);
output.setContent(jsonData);
return output;
}
然后從一個普通的網頁,希望使用jQuery Ajax,你應該能夠獲得Json數據?
簡單的javascript代碼在普通(非GAS)客戶端上會是什么樣子?
看看JSONP看看它應該是什么樣子
此外,它應該是output.setContent(JSON.stringify(jsonData));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.