js调用webservice

[color=red][size=medium]采用sop1.1协议发请求获取列车时刻信息,返回xml数据,未对xml解析。
需要设置浏览器跨域访问,google浏览器通过开始--运行chrome.exe --disable-web-security开启跨域访问。其它浏览器不知道怎么开启这个操作。此操作不安全,请慎用。[/size][/color]


<html>
<head>
<title>列车时刻查询</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
<script>
function search(input) {
var traincode = input.value;
if(traincode) {
var xhr = new XMLHttpRequest();
xhr.open("POST","http://www.webxml.com.cn/WebServices/TrainTimeWebService.asmx", true); //true表示异步,send方法执行完,继续向下执行。等服务器返回数据后,再执行回调方法
xhr.onreadystatechange=function() {
if(xhr.readyState==4) {
if(xhr.status==200) {
alert(xhr.responseText);
alert('revice');
}
}
}

var myxml = '<?xml version="1.0" encoding="utf-8"?>'
+ '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'
+ '<soap:Body>'
+ '<getDetailInfoByTrainCode xmlns="http://WebXml.com.cn/">'
+ '<TrainCode>' + traincode + '</TrainCode>'
+ '<UserID></UserID>'
+ '</getDetailInfoByTrainCode>'
+ '</soap:Body>'
+ '</soap:Envelope>';

xhr.setRequestHeader("SOAPAction","http://WebXml.com.cn/getDetailInfoByTrainCode");
xhr.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xhr.send(myxml);
alert('over');
}
}
</script>
</head>
<body>
请输入车次:<input type="text" name="traincode" onblur="search(this)"/>
</body>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值