webservice获取列车时刻信息

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'traintime.jsp' starting page</title>
    <script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery-1.5.js"></script>
    <script type="text/javascript">
    	$().ready(function() {
    		$("#btn").click(function() {
    			var trainCode = $("#trainCode").val();
    			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>';
    			
				$.ajax({
  				url:'http://webservice.webxml.com.cn/WebServices/TrainTimeWebService.asmx?op=getDetailInfoByTrainCode',
  				dateType:'xml',
  				type:'post',
  				contentType:'text/xml; charset=utf-8',
  				data:myxml,
  				beforeSend: function (xhr) {
                	xhr.setRequestHeader('SOAPAction', 'http://WebXml.com.cn/getDetailInfoByTrainCode');
                },
  				success:function(dt){
  					$("#trainTime").empty();
  					$(dt).find("TrainDetailInfo").each(function(index, domEle) {
  						var $div = $("<div/>");
  						$div.css("color","blue");
  						var $order = $("<span/>");
						$order.text("站次:" + (index + 1) + "        ");
						$div.append($order);
						$(this).children().each(function(index, domEle) {
							if(index == 0) {
								$trainStation = $("<span/>");
								$trainStation.text("站名:" + $(this).text() + "      ");
								$div.append($trainStation);
							}
							if(index == 1) {
								$arriveTime = $("<span/>");
								$arriveTime.text("到达时间:" + $(this).text() + "      ");
								$div.append($arriveTime);
							}
							if(index == 2) {
								$startTime = $("<span/>");
								$startTime.text("开车时间:" + $(this).text() + "      ");
								$div.append($startTime);
							}
						})
						$("#trainTime").append($div);
						$("#trainTime").append($("<br/>")); 
						$("#trainTime").append($("<br/>")); 
  					});
  				}
  			},"xml");
    		});
    	});
    </script>
  </head>
  
  <body>
    请输入车次:<input type="text" id="trainCode"/>
    <button id="btn">查询</button>
    <div id="trainTime"></div>
  </body>
</html>

猜你喜欢

转载自cookieandsession.iteye.com/blog/1901440