Even I am a fan of FF, but this is strange problem I am running through. I am new to ajax and learning to work on it based on what I read online. Here is the code which I wrote which simply fetches the web page and displays on my page. It works well with IE6, but not on FF. I have not tested with IE7 or 8. Kindly have a look at the code below and suggest me changes to make it work on the best browser. <html> <head> <script type="text/javascript"> function testgoogle(){ if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari alert('ff'); xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 alert('old ie'); xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open('get', 'https://www.paypal.com/', true); xmlhttp.onreadystatechange=function() { if(xmlhttp.readyState==4) {document.getElementById('test').innerHTML=xmlhttp.responseText} } xmlhttp.send(null); } </script> </head> <body> <input value="hello" type="button" onclick="testgoogle(null);" /> <div id="test"></div> </body> </html> HTML: Thanks TF
Try this code and you'll see what is the problem: <html> <head> <script type="text/javascript"> function testgoogle(){ if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari alert('ff'); xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 alert('old ie'); xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } try{ xmlhttp.open('get', 'https://www.paypal.com/', true); }catch(e){ alert(e); } xmlhttp.onreadystatechange=function() { if(xmlhttp.readyState==4) {document.getElementById('test').innerHTML=xmlhttp.responseText} } xmlhttp.send(null); } </script> </head> <body> <input value="hello" type="button" onclick="testgoogle(null);" /> <div id="test"></div> </body> </html> Code (markup):
Thanks for your help, but even it did not work. A few minutes back I read that FF does not support cross domain ajax requests as a security feature. Now, I am looking for the methods for that. If you know any method for cross domain requests, kindly inform. MS has recently introduced such feature in IE8 called XDomainRequest. Check it out here: http:// msdn.microsoft.com/en-us/library/cc288060%28VS.85%29.aspx Thanks TF
its not a big drama. you need a proxy. i wrote an example using yahoo's YQL a while back: http://forums.digitalpoint.com/showthread.php?t=1649430&highlight= I just posted this on my blog as it seems like a sore subject for many - http://fragged.org/cross-domain-ajax-calls-via-yql-as-proxy-and-mootools-jsonp_1028.html this uses mootools as framework but there are plenty of ways of doing this via jquery or vanilla js even, if you set your mind to it. do not use xdomainrequest, proprietary and unsupported things are a bad idea regards