本文介绍了从javascript调用asp Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hiii, 我想从(javascript html)代码调用网络服务,我尝试了很多链接, 但它的在我的情况下不工作,我有一个非常简单的web服务运行在 wsjs.sudesi.in/WebService.asmx [ ^ ]返回hello world。如果有人可以使用相同的链接并使用(javascript和html)给我输出,对我来说将是非常有用的。 提前谢谢
Hiii, I want to call web service from (javascript html) code, i tried lots of links, but its not working in my case, i have a very simple web service running on wsjs.sudesi.in/WebService.asmx[^] which return hello world. if somebody can use same link and give me output using (javascript and html), it will be greatly helpfull for me. Thanks in advance
推荐答案<script language="javascript" type="text/javascript"> var soapHeader = '<?xml version="1.0" encoding="utf-8"?>' soapHeader += '<soap:Envelope xmlns:xsi="www.w3/2001/XMLSchema-instance" xmlns:xsd="www.w3/2001/XMLSchema" xmlns:soap="schemas.xmlsoap/soap/envelope/">' soapHeader += '<soap:Body><HelloWorld xmlns="tempuri/" /></soap:Body></soap:Envelope>' //the url of Webservice var postUrl = 'localhost:4174/TestWeb/WebService.asmx'; var soapActionUrl = 'tempuri/HelloWorld'; var xmlhttp = null; try { xmlhttp = new XMLHttpRequest(); }catch (e) {xmlhttp = false; } try { xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); }catch (e) { xmlhttp = false; } try { xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');}catch (e) { xmlhttp = false; } alert(xmlhttp); if( xmlhttp ) { xmlhttp.open ('POST', postUrl, true); xmlhttp.onreadystatechange = function() { if( xmlhttp.readyState == 4 ) { alert(xmlhttp.responseText); } }; xmlhttp.setRequestHeader('Content-Type', 'text/xml; charset=utf-8'); xmlhttp.setRequestHeader("Host", "localhost"); xmlhttp.setRequestHeader("SOAPAction", soapActionUrl); xmlhttp.setRequestHeader("Content-Length", soapHeader.length ); xmlhttp.send(soapHeader); } </script>
好文章你可以这个使用JavaScript调用Web服务 [ ^ ]
哈哈...... 最后我找到了它... i使用jquery来检索我的数据.... ha ha... finally i found it... i used jquery to retrieve my data.... <html> <head> <title>Calling Web Service from jQuery</title> <script type="text/javascript" src="ajax.googleapis/ajax/libs/jquery/1.4.3/jquery.min.js"></script> <script type="text/javascript">
(document).ready(function( ){ (document).ready(function () {
更多推荐
从javascript调用asp.net Web服务
发布评论