zoukankan      html  css  js  c++  java
  • JQuery跨域请求

    javascript可跨域请求:

    <html>
    	<head>
    		<title>通过ajax调用WebService服务</title>
    		<script>
    			
    			var xhr = new ActiveXObject("Microsoft.XMLHTTP");
    			function sendMsg(){
    				var name = document.getElementById('name').value;
    				//服务的地址
    				var wsUrl = 'http://localhost:8080/php';
    				
    				//请求体
    				
    										 
    				var soap = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0="http://ws.cxf.php.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><q0:sayHello><arg0>'+name+'</arg0></q0:sayHello></soapenv:Body></soapenv:Envelope>'
    									 
    				//打开连接
    				xhr.open('POST',wsUrl,true);
    				
    				//重新设置请求头
    				xhr.setRequestHeader("Content-Type","text/xml;charset=UTF-8");
    				
    				//设置回调函数
    				xhr.onreadystatechange = _back;
    				
    				//发送请求
    				xhr.send(soap);
    			}
    			
    			function _back(){
    				if(xhr.readyState == 4){
    					if(xhr.status == 200){
    							//alert('调用Webservice成功了');
    							var ret = xhr.responseXML;
    							var msg = ret.getElementsByTagName('return')[0];
    							document.getElementById('showInfo').innerHTML = msg.text;
    							//alert(msg.text);
    						}
    				}
    			}
    		</script>
    	</head>
    	<body>
    			<input type="button" value="发送SOAP请求" onclick="sendMsg();">
    			<input type="text" id="name">
    			<div id="showInfo">
    			</div>
    	</body>
    </html>
    
  • 相关阅读:
    poj 2757 : 最长上升子序列(JAVA)
    POJ 2760: 数字三角形
    poj 1664:放苹果
    Poj 2756:二叉树
    poj机上的JAVA那些事儿
    浅谈HASH算法与CSDN密码泄漏事件
    如何防范密码被破解
    [转载自百度文库]数组拷贝(System.arraycopy,深度拷贝)--数组
    Java数学计算
    fzu Problem 1396 Large Caclulating Work
  • 原文地址:https://www.cnblogs.com/dapeng520/p/4622809.html
Copyright © 2011-2022 走看看