【求助-急】-- js 调用webservice返回空,并且status为0

qq_18540635 2015-02-12 04:04:39
js调用webservice status一直为0,改为天气这个web服务后,还是为0,是哪出问题了,求助,急。下面贴下代码

var xmlhttp;
function RequestByPost() {
var URL = "http://www.webxml.com.cn/WebServices/WeatherWS.asmx";

//在这处我们拼接
var data;
data = '<?xml version="1.0" encoding="utf-8"?>';
data = data + '<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">';
data = data + '<soap12:Body>';
data = data + '<getRegionCountry xmlns="http://tempuri.org/" />';
data = data + '</soap12:Body>';
data = data + '</soap12:Envelope>';

//创建异步对象
var xmlhttp = createXmlHttpRequest();
xmlhttp.open("POST", URL, true);
xmlhttp.setRequestHeader("Content-Type", "application/soap+xml; charset=utf-8");
xmlhttp.send(data);

// alert(xmlhttp.responseText);

}

function createXmlHttpRequest() {

if (window.XMLHttpRequest) {
xmlhttp = new window.XMLHttpRequest()
}
else {
xmlhttp = new ActiveXObject("Microsoft.XMLHttp");
}
return xmlhttp;
}

function callback() {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200 ) { //xmlhttp.status为0,可这个已经发布了啊
var response = xmlhttp.responseText;
alert(response);
}
}
}
...全文
176 2 打赏 收藏 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_18540635 2015-02-12
  • 打赏
  • 举报
回复
引用 1 楼 cia426 的回复:
var URL = "http://www.webxml.com.cn/WebServices/WeatherWS.asmx"; 你的url并没有指定要去请求ws的哪个方法
在open之后有设置请求头,帖子发的急,没贴上 网上很多调用web服务的,可试着不行啊 xmlhttp.open("GET", URL, true); xmlhttp.onreadystatechange = callback; xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); xmlhttp.setRequestHeader("SOAPAction", "http://tempuri.org/getRegionCountry"); xmlhttp.send(data);
cia426 2015-02-12
  • 打赏
  • 举报
回复
var URL = "http://www.webxml.com.cn/WebServices/WeatherWS.asmx"; 你的url并没有指定要去请求ws的哪个方法

87,984

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧