[英]how to send put request with data as an xml element, from JavaScript?
我的数据是xml元素,我想使用JavaScript发送PUT请求。 我该怎么做呢 ?
供参考: 更新单元
编辑:根据弗雷德里克建议,我这样做:
<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。 还有其他解决方案吗?
由于HTTP协议仅支持发送字符串,因此不确定您是否能够执行此操作。 但是,您可以尝试使用jQuery的ajax方法并将该方法更改为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);
}
});
希望它能工作。
编辑 :请提供一些有关您正在尝试做的信息/代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.