sunilvadranapu Posted April 1, 2008 Share Posted April 1, 2008 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 Quote Link to comment Share on other sites More sharing options...
nogray Posted April 1, 2008 Share Posted April 1, 2008 Here is a good tutorial on how to use ajax http://www.w3schools.com/AJAX/default.asp Quote Link to comment Share on other sites More sharing options...
haku Posted April 2, 2008 Share Posted April 2, 2008 I can shed some light - your script is trying to access a site on another domain, therefore that information is not under its control. As such, you get a warning. Quote Link to comment Share on other sites More sharing options...
sunilvadranapu Posted April 3, 2008 Author Share Posted April 3, 2008 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 Quote Link to comment Share on other sites More sharing options...
haku Posted April 3, 2008 Share Posted April 3, 2008 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. Quote Link to comment Share on other sites More sharing options...
lordfrikk Posted April 3, 2008 Share Posted April 3, 2008 That's right, haku. You can't do it as you would've wanted, sunil, because it's considered Cross-Site XHR (XMLHttpRequest). You might want to read some info here: http://cows-ajax.sourceforge.net/tech.php Quote Link to comment Share on other sites More sharing options...
sunilvadranapu Posted April 9, 2008 Author Share Posted April 9, 2008 Thanks for your replies. Can you give me an example for invoking web service "isIP" (developed in C#) from PHP and passing result to xmlhttprequest of Java script function. thanks in advance. -sunil Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.