Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Firefox XMLHttpRequest not working

Status
Not open for further replies.

firsttube

Technical User
Apr 21, 2004
165
CA
I have been banging my head against the wall on this one.

Here is the code I have:
Code:
var url = "[URL unfurl="true"]http://myurl.com/getData.asp?type="[/URL] + type + "&what=" + what + "&where=" + where;
	if(window.XMLHttpRequest) {
		var req = new XMLHttpRequest();	
	} else if(window.ActiveXObject) {
		var req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	req.open("GET", url, true);
	req.send(null);
if (document.implementation && document.implementation.createDocument)
	{
		var strXML = document.implementation.createDocument("","",null);
		strXML.async = false;
		alert(req.responseText);
		strXML.load(req.responseText);

} else if (window.ActiveXObject) {
		var strXML = new ActiveXObject("Microsoft.XMLDOM");
		strXML.async = false;
		strXML.loadXML(req.responseText)
		alert(req.responseText);
}
It works in IE, but not in FF. The line for alert(req.responseText) shows in IE but in FF it is empty and there are no errors in the javascript console.

any ideas?


Information is not Knowledge, Knowledge is not Wisdom, Wisdom is not Truth, Truth is not Beauty, Beauty is not Love, Love is not Music, Music is the best.
 
[1] You do not implement onreadystatechange handler, so there would be a timing problem. You should therefore use synchronous version to guard against the timing problem.

>req.open("GET", url, true);
[tt]req.open("GET", url, [red]false[/red]);[/tt]

[2] You should set the netscape security manager on "UniversalBrowserRead" for cross-browser scripting. Like this.
[tt]
if(window.XMLHttpRequest) {
var req = new XMLHttpRequest();
[blue]try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
} catch (e) {
alert("Permission could be denied for cross-browser scripting.");
}[/blue]
} else if(window.ActiveXObject) {
var req = new ActiveXObject("Microsoft.XMLHTTP");
}
[/tt]
 
Amendment
The message in the alert should be read like this.
[tt]
alert("Permission could be denied for cross-[red]domain[/red] scripting.");
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top