1

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.com/KB/webservices/callWebServiceUsingJS.aspx

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

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

Please help me. Thanks

5
  • Does http://myURL/cloudtalk/cloudservice.asmx?wsdl in your browser? Commented Feb 23, 2011 at 7:01
  • What about not using IE-only stuff? Commented Feb 23, 2011 at 7:03
  • @i wants to consume my service in all browsers using javascript Commented Feb 23, 2011 at 7:05
  • @deiga:my web service is live and i am able to consume it using asp.net but i am facing issue for using it in javascript. Commented Feb 23, 2011 at 7:06
  • I think its not working because of cross domain, experts is it correct? Commented Feb 23, 2011 at 7:21

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.