severndigital Posted December 10, 2010 Share Posted December 10, 2010 I have a simple piece of code function getURL() { var xmlhttp = new XMLHttpRequest(); var url = "http://mydomain.org/service/"; xmlhttp.open("GET", url, false); xmlhttp.send(null); var returnValue = xmlhttp.responseText; document.write(returnValue); } when I change the xmlhttp var to new ActiveXObject("Microsoft.XMLHTTP"); and run this in IE .. it works fine. when I try to run it as is I get the following errors from firebug. uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIXMLHttpRequest.send]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: http://cyan/music-print/test :: getURL :: line 13" data: no] Line 0 everything shows up fine, when I try to access the url directly from firefox. It is just a simple xml document. Thanks in advance. Chris Quote Link to comment https://forums.phpfreaks.com/topic/221219-works-in-ie7-but-not-firefox/ Share on other sites More sharing options...
Adam Posted December 13, 2010 Share Posted December 13, 2010 The problem is likely down to you trying to access xmlhttp.responseText before it's available. You need to bind the handling code to the 'onreadystatechange' event, and only attempt to use the response text once it's ready: xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { var returnValue = xmlhttp.responseText; document.write(returnValue); } } That bound function will be called several times and only when the ready state is 4 (ready) will the response be handled. There's also a check to make sure the HTTP status returned was 200 (OK). Quote Link to comment https://forums.phpfreaks.com/topic/221219-works-in-ie7-but-not-firefox/#findComment-1146710 Share on other sites More sharing options...
severndigital Posted December 14, 2010 Author Share Posted December 14, 2010 that didn't seem to work either. It seems like it works from the local server, but I am trying to access as remote webservice. Is there something else I need to do? Again, it works fine through IE but not FF. Thanks, Quote Link to comment https://forums.phpfreaks.com/topic/221219-works-in-ie7-but-not-firefox/#findComment-1147157 Share on other sites More sharing options...
Adam Posted December 14, 2010 Share Posted December 14, 2010 Remote service? AJAX isn't cross-domain. Quote Link to comment https://forums.phpfreaks.com/topic/221219-works-in-ie7-but-not-firefox/#findComment-1147160 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.