我的数据是一个xml元素&我想用JavaScript发送PUT请求。我该怎么做?
供参考:Update Cell
编辑: 根据弗雷德里克的建议,我这样做了:
<form id="submitForm" method="PUT" enctype="application/atom+xml" action="https://spreadsheets.google.com/feeds/cells/0Aq69FHX3TV4ndDBDVFFETUFhamc5S25rdkNoRkd4WXc/od6/private/full/R2C1">
<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gs='http://schemas.google.com/spreadsheets/2006'>
<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/od6/private/full/R2C1'/>
<gs:cell row='2' col='1' inputValue='300'/>
</entry>
<input type="submit" value="submit"/>
</form>
但是,它不会回写,但肯定会返回xml文件,如:
<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gs='http://schemas.google.com/spreadsheets/2006' xmlns:batch='http://schemas.google.com/gdata/batch'>
<id>https://spreadsheets.google.com/feeds/cells/0Aq69FHX3TV4ndDBDVFFETUFhamc5S25rdkNoRkd4WXc/od6/private/full/R2C1</id>
<updated>2011-01-11T07:35:09.767Z</updated>
<category scheme='http://schemas.google.com/spreadsheets/2006' term='http://schemas.google.com/spreadsheets/2006#cell'/>
<title type='text'>A2</title>
<content type='text'></content>
<link rel='self' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/cells/0Aq69FHX3TV4ndDBDVFFETUFhamc5S25rdkNoRkd4WXc/od6/private/full/R2C1'/>
<link rel='edit' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/cells/0Aq69FHX3TV4ndDBDVFFETUFhamc5S25rdkNoRkd4WXc/od6/private/full/R2C1/1ekg'/>
<gs:cell row='2' col='1' inputValue=''></gs:cell>
</entry>
这里,inputvalue是空的!但是,在我的xml字符串中它是300。 任何进一步的解决方案?
答案 0 :(得分:1)
由于HTTP协议仅支持发送字符串,因此我不确定您是否能够执行此操作。但您可以尝试使用jQuery's ajax method并将方法更改为PUT和内容类型并发送序列化的XML。
jQuery文档说:
要求的类型(“POST”或“GET”),默认为“GET”。注意:此处也可以使用其他HTTP请求方法,例如PUT和DELETE,但并非所有浏览器都支持它们。
调用ajax调用:
$.ajax({
url: 'ajax/test.html',
type: 'PUT',
contentType: 'text/xml',
processData: false,
data: xmlDocument,
success: function(data) {
console.log(data);
}
});
希望它有效。
修改强>: 请提供一些有关您要做的事情的更多信息/代码。