从javascript调用asp.net Web服务

编程入门 行业动态 更新时间:2024-10-28 20:27:24
本文介绍了从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服务

本文发布于:2023-10-29 13:30:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539822.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:asp   javascript   Web   net

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!