【发布时间】:2011-01-12 10:16:17
【问题描述】:
我必须以编程方式写入我的电子表格。它允许我写入电子表格的特定单元格。我的代码是:
function update(){
jQuery.ajax({
type: 'PUT',
contentType: "application/atom+xml",
url: "https://spreadsheets.google.com/feeds/cells/0Aq69FHX3TV4ndDBDVFFETUFhamc5S25rdkNoRkd4WXc/od6/private/full/R2C1",
dataType: "xml",
data: "new.xml",
success: function() {
alert('Put Success');
},
error: function(a,b,c) {
console.log("XMLHttpRequest: " + a);
console.log("textStatus: " + b);
console.log("errorThrown: " + c);
alert("XMLHttpRequest : " + a + " textStatus : " + b + " errorThrown : " + c);
}
});
}
我只能使用 xml 元素写入电子表格。所以,我创建了(new.xml):
<entry>
<id>https://spreadsheets.google.com/feeds/cells/0Aq69FHX3TV4ndDBDVFFETUFhamc5S25rdkNoRkd4WXc/od6/private/full/R2C1</id>
<link rel="edit" type="application/atom+xml"
href="https://spreadsheets.google.com/feeds/cells/0Aq69FHX3TV4ndDBDVFFETUFhamc5S25rdkNoRkd4WXc/worksheetId/private/full/R2C1"/>
<gs:cell row="2" col="1" inputValue="300"/>
</entry>
但是,我的代码仍然抛出错误。我认为这与我正在编写的 XML 文件有关。我认为,创建 new.xml 是我的错误。请建议如何写回?如何创建 xml 元素?
供参考:Update Cells
输出: A : [对象对象]
b: 未定义
c:
【问题讨论】:
-
如果您告诉我们错误是什么可能会有所帮助!但是,我怀疑问题在于您试图 PUT 一个由文件名而不是 XML 组成的字符串(即
data: 'new.xml'应该是data: '<entry><id>etc etc。 -
data : '
...' 不是正确的字符串并给出错误。让我添加上一个案例中的错误。
标签: javascript jquery xml ajax google-sheets