开发者

How To Post XML via JavaScript to REST API?

I'm trying to POST XML via JavaScript to a REST API.

The Request Data looks like this:

<?xml v开发者_如何学Goersion="1.0" encoding="UTF-8" standalone="yes"?>
<EditGame xmlns="http://blahblahblah.com" >
<playerCount>2</playerCount>
<score>2621440</score>
</EditGame>

How do I define the postString above if my code looks like this below:

xhr.open('POST',URLgameUpdateAction);
xhr.setRequestHeader('Content-type','application/x-www.form-urlencoded');
xhr.send(**postString**);

Hope this makes sense.


You can pass the XML as a simple string.

xhr.open('POST',URLgameUpdateAction);
xhr.setRequestHeader('Content-type','application/x-www.form-urlencoded');
xhr.send("\
  <?xml version='1.0' encoding='UTF-8' standalone='yes'?>\
  <EditGame xmlns='http://blahblahblah.com'>\
  <playerCount>2</playerCount>\
  <score>2621440</score>\
  </EditGame>\
");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜