从javascript调用asp.net Web服务 [英] call asp.net web service from javascript
本文介绍了从javascript调用asp.net Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hiii,
我想从(javascript html)代码调用网络服务,我尝试了很多链接,
但它的在我的情况下不工作,我有一个非常简单的web服务运行在 http://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 http://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="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'
soapHeader += '<soap:Body><HelloWorld xmlns="http://tempuri.org/" /></soap:Body></soap:Envelope>'
//the url of Webservice
var postUrl = 'http://localhost:4174/TestWeb/WebService.asmx';
var soapActionUrl = 'http://tempuri.org/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="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script type="text/javascript">
(document).ready(function( ){
(document).ready(function () {
这篇关于从javascript调用asp.net Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文