最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

web services - How to call webservice using javascript - Stack Overflow

programmeradmin3浏览0评论

I am using below code to call webservice using javascript:

<head>
    <title>Untitled Page</title>
       <script type="text/javascript" language="JavaScript">
      service = document.getElementById("ViewLink");

     function InitializeService(){
      service.useService('http://myURL/cloudtalk/cloudservice.asmx?wsdl',"CloudService");
     }
     var regtype, regvalue;
     function registerUser(){
      regtype = document.getElementById("Text1").value;
      regvalue =document.getElementById("Text2").value;

      service.CloudService.callService("register", regtype, regvalue);
     }
     function ShowResult(){
    alert(event.result.value);
      }
     </script>
</head>
<body  onload="InitializeService()" id="service" >
<a id="ViewLink"   href="http://"  onclick="registerUser()"  style="behavior:url(webservice.htc);" onresult="onmyresult();"> <font color=maroon>Call</font></a>
  <input id="Text1" type="text" />
        <input id="Text2" type="text" />
        <input id="Button1" type="button" value="Save" onclick="registerUser();" />     
</body>

But i am getting error:"The url is not valid and cannot be loaded"

i done the above code with help of below urls but i checked both samples in these url are not working:

.aspx

.aspx

NOTE: my web service is live and i am able to consume it using asp but i am facing issue for using it in javascript.

Please help me. Thanks

I am using below code to call webservice using javascript:

<head>
    <title>Untitled Page</title>
       <script type="text/javascript" language="JavaScript">
      service = document.getElementById("ViewLink");

     function InitializeService(){
      service.useService('http://myURL/cloudtalk/cloudservice.asmx?wsdl',"CloudService");
     }
     var regtype, regvalue;
     function registerUser(){
      regtype = document.getElementById("Text1").value;
      regvalue =document.getElementById("Text2").value;

      service.CloudService.callService("register", regtype, regvalue);
     }
     function ShowResult(){
    alert(event.result.value);
      }
     </script>
</head>
<body  onload="InitializeService()" id="service" >
<a id="ViewLink"   href="http://"  onclick="registerUser()"  style="behavior:url(webservice.htc);" onresult="onmyresult();"> <font color=maroon>Call</font></a>
  <input id="Text1" type="text" />
        <input id="Text2" type="text" />
        <input id="Button1" type="button" value="Save" onclick="registerUser();" />     
</body>

But i am getting error:"The url is not valid and cannot be loaded"

i done the above code with help of below urls but i checked both samples in these url are not working:

http://www.codeproject./KB/webservices/callWebServiceUsingJS.aspx

http://www.codeproject./KB/webservices/CallWebServiceFromHtml.aspx

NOTE: my web service is live and i am able to consume it using asp but i am facing issue for using it in javascript.

Please help me. Thanks

Share Improve this question edited Feb 23, 2011 at 7:04 Dr. Rajesh Rolen asked Feb 23, 2011 at 6:59 Dr. Rajesh RolenDr. Rajesh Rolen 14.3k42 gold badges110 silver badges180 bronze badges 5
  • Does http://myURL/cloudtalk/cloudservice.asmx?wsdl in your browser? – deiga Commented Feb 23, 2011 at 7:01
  • What about not using IE-only stuff? – ThiefMaster Commented Feb 23, 2011 at 7:03
  • @i wants to consume my service in all browsers using javascript – Dr. Rajesh Rolen Commented Feb 23, 2011 at 7:05
  • @deiga:my web service is live and i am able to consume it using asp but i am facing issue for using it in javascript. – Dr. Rajesh Rolen Commented Feb 23, 2011 at 7:06
  • I think its not working because of cross domain, experts is it correct? – Dr. Rajesh Rolen Commented Feb 23, 2011 at 7:21
Add a ment  | 

1 Answer 1

Reset to default 5

If the web service URL has a different host (by domain name or port) than the one from which the HTML page is served then your JavaScript is violating the same origin policy and any browser will prevent the web service request from loading.

发布评论

评论列表(0)

  1. 暂无评论