简体   繁体   English

xmlhttp send从XML文件发送单个对象

[英]xmlhttp send to send a single object from a XML file

I am currently using xmlhttp send to PUT something back onto the webservice: 我目前正在使用xmlhttp将某些内容发送回PUT到Web服务上:

My XML : 我的XML:

<collection>
 <beanRepresentation>
  <beanRepId>1323</beanRepId>
  <beanRepName>john</beanRepName>
 </beanRepresentation>

  ...more <beanRepresentations> ..

</collection>

I pull this XML, make some changes using through my HTML page. 我提取此XML,并通过HTML页面进行一些更改。 And now I want to use PUT to update the changes I made to beanRepresenetation. 现在,我想使用PUT更新对beanRepresenetation所做的更改。

I do not want to update the whole XML, just the single object I made changes in. I am doing it like the following: 我不想更新整个XML,而只想更新更改过的单个对象。我这样做如下:

xmlhttp.open("PUT","http://localhost:8080/rest/beanRepresentation",
                                    false);
xmlhttp.setRequestHeader("Content-type","application/xml");
xmlhttp.send((xmlDoc.getElementsByTagName("beanRepresentation")[0]));

firebug says: 萤火虫说:

PUT http://localhost:8080/rest/beanRepresentation 400 Bad Request

and the Source shows this is what I am sending: 源显示这是我发送的内容:

[object Element]

This is the problem, why aren't I sending this back: 这是问题,为什么我不发送回去:

<collection>
 <beanRepresentation>
  <beanRepId>1323</beanRepId>
  <beanRepName>Updated Name</beanRepName>
 </beanRepresentation>

</collection>

?? ?? I need it to PUT it back like the above format, not " [Object Element] ". 我需要它像上述格式一样将其放回去,而不是“ [Object Element] ”。

弄清楚了:

xmlhttp.send((new XMLSerializer()).serializeToString(xmlDoc.getElementsByTagName("beanRepresentation")[i]));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM