Jump to content

Invoke webservice from javascript


sunilvadranapu

Recommended Posts

Hi,

  I have designed a form with text box for reading IP address and onChange method of textbox i am calling a  javascript function to validate IP address entered in the textbox.

  In java script function, i am  invoking a web service developed in C# which is on different domain. when i am running this page getting the warning message "This page is accessing information that is not under its control. This poses a security risk. Do you want to continue?"

 

  my java script function is:

<CODE> 

function validateIPAddress(sysName)

{

  var ret;

  var QueryString = "http://sunil/misc/misc.asmx/isIP?IPaddress=" +sysName;

 

  var xmldoc=new ActiveXObject("Microsoft.XMLDOM");

  xmldoc.async = false;

  xmldoc.load(QueryString);

  oNodeList = xmldoc.documentElement.childNodes;

 

  ret = oNodeList.item(0).text;

  if( ret == "BAD_ADDRESS")

return false;

  else

return true;

}

</CODE>

 

 

Could any one shed some light on this.

 

Thanks in advance

 

 

-sun

Link to comment
Share on other sites

Hi,

thanks for your reply. Is there any other way to access the web service on different domain. i tried to access with "xmlhttprequest", but even then getting same problem

var xmlhttp;
function validateIPAddress1(sysName)
{
    url="http://sunil/misc/misc.asmx/isIP?IPaddress=" +sysName;
    xmlhttp=null;
    if (window.XMLHttpRequest)
    {
        xmlhttp=new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {                      // code for IE5 and IE6
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    if (xmlhttp!=null)
    {
      xmlhttp.open("GET",url,true);
      xmlhttp.onreadystatechange=function() {
          if (xmlhttp.readyState==4) {
        
          var myXml = xmlhttp.responseXML;
          var xmlobject = null;
          var XMLText = null;
          if (window.ActiveXObject)
          {
            XMLText = myXml.childNodes[1].firstChild.nodeValue;
            alert(XMLText);
          }
          else
          {
            XMLText = myXml.childNodes[0].firstChild.nodeValue;
            alert(XMLText);
          }
        }
      }
      xmlhttp.send(null);
    }
    else
    {
        alert("Your browser does not support XMLHTTP.");
    }
}

 

any suggestions???

 

thanks in advance

 

 

-sunil

Link to comment
Share on other sites

Yes, there is something you can do about it. If you try to directly access information on another site with an Ajax script, you get the warning you are getting. So what you have to do is write a server-side script (PHP, ASP, PERL etc) that accesses the other domain, and then passes the information to your XMLHttpRequest. If you do this, you won't get an error message because that access happens on the server, not on the client.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.