jQuery .ajax POST到Spreadsheets API? [英] JQuery .ajax POST to Spreadsheets API?

查看:100
本文介绍了jQuery .ajax POST到Spreadsheets API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过JavaScript/JQuery在Google电子表格中添加新行.我不知道该怎么做,但这是我的尝试:

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 :(

推荐答案

我不确定要使用jQuery ajax api,但是您可以尝试按如下所示构造xml条目并按如下所示设置参数.

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.

也许其他人可以展示如何使用jQuery API?

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);

这篇关于jQuery .ajax POST到Spreadsheets API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆