HTML5帖子请求正文

Yat*_*tin 5 xml ajax web-services xmlhttprequest

function sendPost(){

alert("IN SEND POST");


var username = document.myForm.username.value;
var password = document.myForm.password.value;
alert("username"+username);
alert("password"+password);

console.log("in java script");

    var url = "some url";

    alert("IN url SEND POST");

    var data = "<MESSAGE><HEADER><LOGIN>005693</LOGIN></HEADER><SESSION><LATITUDE>0.0</LATITUDE><LONGITUDE>0.0</LONGITUDE><APP>SRO</APP><ORG>MNM</ORG><TRANSACTION>PRELOGIN</TRANSACTION><KEY>PRELOGIN/ID</KEY><TYPE>PRELOGIN</TYPE></SESSION><PAYLOAD><PRELOGIN><ID>005693</ID><USERNAME>005693</USERNAME><PASSWORD>tech@2014</PASSWORD></PRELOGIN></PAYLOAD></MESSAGE>";

console.log("2")

    var req;
    if(window.XMLHttpRequest) {
    console.log("2");
    try {
      req = new XMLHttpRequest();
    } catch(e) {
      req = false;
    }
  }
  else if(window.ActiveXObject) {
  console.log("3");
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
      try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      } catch(e) {
        req = false;
      }
    }
  }


  console.log("4");
  req.onreadystatechange=function()
  {
  console.log("5");
  if (req.readyState==4 && req.status==200)
    {
    console.log("ready state accepted");
    xmlDoc=req.responseXML;
     console.log("xmlDoc"+xmlDoc);
     alert("xmlDoc"+xmlDoc);
    txt="";
    x=xmlDoc.getElementsByTagName("FIRSTNAME");
    y=xmlDoc.getElementsByTagName("LASTNAME");
     console.log("Response achieved"+x);
    }


  }


req.open("POST",url,true);
console.log("6");
req.setRequestHeader("Content-type","application/xml");
req.send(data);
 console.log("7");
  return true;
  }
Run Code Online (Sandbox Code Playgroud)

我完全像我想要的那样在休息客户端得到回应

在Google Chrome中 - >我的状态为0,就绪状态为1,然后是4在Internet Explorer中 - >我的状态为200 OK,就绪状态为1,2,3,4,但返回空白xml

在休息客户端,我得到一个完美的命中,并返回一个xml

我尝试用不同的方式提问,但有些人说它是一个交叉起源的问题如果是的话请通过javascript中的代码知道解决方案

请指导

REST客户端图像

Que*_*tin 3

服务器表示它正在发送text/plain数据,而不是 XML,因此浏览器不会填充req.responseXML. 数据应该在req.responseText.

  • “数据应该位于 req.responseText 中。” (2认同)
  • 是的。如果标头可以由*想要*权限的页面设置,那么标头中就没有太多意义。 (2认同)