【发布时间】:2014-02-12 10:43:00
【问题描述】:
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;
}
我在休息客户端中得到了完美的响应,如图所示
在 Google Chrome 中 --> 我的状态为 0,就绪状态为 1,然后是 4 在 Internet Explorer 中 --> 我的状态为 200 OK,就绪状态从 1 , 2, 3, 4 但返回一个空白 xml
在休息客户端我得到一个完美的命中并返回一个 xml
我尝试以不同的方式提问,但有人说这是一个跨源问题 如果是,请通过javascript中的代码了解解决方案
请指导
【问题讨论】:
-
您多次被要求检查 JS 错误控制台并查看浏览器开发人员工具中的 Net 选项卡,以便调试此问题。你似乎还没有这样做。
-
如果您的问题不是以这样一种方式形成的,您可以得到一个好的答案,那么编辑问题;不要一遍又一遍地问……
-
我在 console.log 行中收到一个错误......但是当我评论它时没有任何反应......它只是通过它有什么问题???
-
“一个错误”。 什么错误?
-
请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,不允许访问 Origin 'null'。
标签: ajax xml web-services xmlhttprequest