Reputation: 708
I am trying to add a new row in a google spreadsheet via JavaScript/JQuery. I have no idea how to do this, but here is my attempt:
var myJSONObject = {"entry": [
"gsx:name": name,
"gsx:email": email,
"gsx:phone": phone,
"gsx:guests": guests
]}
var json_uri = "https://spreadsheets.google.com/feeds/list/" + KEY + "/" + id + "/" + SECURE + "/values?alt=json"
$.ajax({
type: "POST",
url: json_uri,
//contentType: 'application/json',
data: myJSONobject
dataType: 'json',
success: function(data){
alert("row added!");
},
error: function(){
alert("error");
}
});
but I keep getting the error :(
Upvotes: 0
Views: 1581
Reputation: 676
I'm not sure about using the jQuery ajax api but you might try constructing an xml entry as below and setting your parameters as shown.
Perhaps someone else can show how to do it with the jQuery api?
gdocs.constructSpreadAtomXml_ = function(name, email, phone, guests) {
var atom = ["<?xml version='1.0' encoding='UTF-8'?>",
'<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gsx="http://schemas.google.com/spreadsheets/2006/extended">',
'<gsx:name>',name,'</gsx:title>',
'<gsx:email>',email,'</gsx:url>',
'<gsx:phone>',phone,'</gsx:summary>',
'<gsx:guests>',guests,'</gsx:tags>',
'</entry>'].join('');
return atom;
};
...
var params = {
'method': 'POST',
'headers': {
'GData-Version': '3.0',
'Content-Type': 'application/atom+xml'
},
'body': gdocs.constructSpreadAtomXml_(name, email, phone, guests)
};
var worksheetId = 'od6'; //The first worksheet.
var url = 'https://spreadsheets.google.com/feeds'+'/list/'+docId+'/'+worksheetId+'/private/full';
//sends the params to the background page to get delivered to gDocs
oauth.sendSignedRequest(url, handleSuccess, params);
Upvotes: 1