PDA

View Full Version : Ajax script doesn't work in FireFox



codeexploiter
09-27-2006, 07:35 AM
Hi all,

I am dealing with an Ajax script and it works pretty good in IE 6.0 but not in Firefox based browsers.

In the javascript console it gives the following error code (red color)

Error: uncaught exception: [Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: http://localhost/login.js :: loginUser :: line 74" data: no

Why this is happening only in firefox? :(

The firefox browser version i am using is 1.5.0.7

thanks in advance

regards

Code Exploiter

tech_support
09-27-2006, 07:42 AM
You might want to give us a link for the ajax script :)

codeexploiter
09-27-2006, 07:44 AM
It is working in a private network won't be able to host in public

Plz find the ajax script below


var XMLHTTPREQUEST_MS_PROGIDS = new Array(
"Msxml2.XMLHTTP.7.0",
"Msxml2.XMLHTTP.6.0",
"Msxml2.XMLHTTP.5.0",
"Msxml2.XMLHTTP.4.0",
"MSXML2.XMLHTTP.3.0",
"MSXML2.XMLHTTP",
"Microsoft.XMLHTTP"
);

var XMLHTTPREQUEST_READY_STATE_UNINITIALIZED = 0;
var XMLHTTPREQUEST_READY_STATE_LOADING = 1;
var XMLHTTPREQUEST_READY_STATE_LOADED = 2;
var XMLHTTPREQUEST_READY_STATE_INTERACTIVE = 3;
var XMLHTTPREQUEST_READY_STATE_COMPLETED = 4;

var myXmlHttpRequest;
var theFrame;
var theUser = "";

function getXMLHttpRequest()
{
alert('http request');
var httpRequest = null;
if (window.XMLHttpRequest != null) {
httpRequest = new window.XMLHttpRequest();
httpRequest.overrideMimeType('text/xml');
alert('activex supported 1');
} else if (window.ActiveXObject != null) {
var success = false;
for (var i = 0;
i < XMLHTTPREQUEST_MS_PROGIDS.length && !success;
i++)
{
try
{
httpRequest = new ActiveXObject(XMLHTTPREQUEST_MS_PROGIDS[i]);
success = true;
alert('activex supported 2');
}
catch (ex) {
alert('activex not supported ex');
}
}
}
if (httpRequest == null)
alert("Error in HttpRequest():\n\n"+ "Cannot create an XMLHttpRequest object.");
return httpRequest;
}

function loadFrame(frm, page, user, pswd) {
theFrame = frm;
theUser = user;
var lblStatus = theFrame.document.getElementById('lblStatus');
if (lblStatus != null) {
lblStatus.style.visibility="visible";
}
myXmlHttpRequest = getXMLHttpRequest();
alert(myXmlHttpRequest);
var encodedStr='Basic '+encode64(user+ ':' +pswd);
myXmlHttpRequest.open('GET',page, true);
isBusy = true;
myXmlHttpRequest.onreadystatechange = loginUser();
myXmlHttpRequest.setRequestHeader("Authorization", encodedStr);
myXmlHttpRequest.setRequestHeader("User-Agent", "login");
myXmlHttpRequest.send("");

}

function loginUser(){

alert(myXmlHttpRequest);
if(myXmlHttpRequest.readyState == 4){
if(myXmlHttpRequest.status == 200 ){


var resText=myXmlHttpRequest.responseTEXT;
alert("resText"+resText);
var newString=resText.replace(/@@@@/g, theUser);
theFrame.document.writeln(newString);
theFrame.document.close();
} else if(myXmlHttpRequest.status == 403){
var lblStatus = theFrame.document.getElementById('lblStatus');
if (lblStatus != null) {
lblStatus.style.visibility="hidden";
}
alert('Invalid User Name or Password. \nPlease try again.\n');
theFrame.reload(true);
} else {
var lblStatus = theFrame.document.getElementById('lblStatus');
if (lblStatus != null) {
lblStatus.style.visibility="hidden";
}
alert('Invalid User Name or Password. \nPlease try again.\n');
alert('error - could not access the pump');
}
}


}


function encode64(input)
{
var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789=';
var output = '';
var chr1, chr2, chr3 = '';
var enc1, enc2, enc3, enc4 = '';
var i = 0;

do {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);

enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;

if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else if (isNaN(chr3)) {
enc4 = 64;
}

output = output +
keyStr.charAt(enc1) +
keyStr.charAt(enc2) +
keyStr.charAt(enc3) +
keyStr.charAt(enc4);
chr1 = chr2 = chr3 = '';
enc1 = enc2 = enc3 = enc4 = '';
} while (i < input.length);

return output;
}

and it creates the problem in Firefox when it encounter the following line


myXmlHttpRequest.status

BLiZZaRD
09-27-2006, 08:04 AM
I am not a JS or AJAX guy, but I came accross this thread: http://www.thescripts.com/forum/threadnav436534-2-10.html

and in it, someone had the exact same error with the exact same line. I read it but made me dizzy. I *think* it got fixed.

Hope it helps :)

codeexploiter
09-27-2006, 12:19 PM
I've figured it out now it works without any probs

mwinter
09-27-2006, 12:23 PM
It is working in a private network won't be able to host in public

True, but you could produce a public example that demonstrates the problem.



httpRequest.overrideMimeType('text/xml');

If you use that method at all, you should test for it first. Opera didn't support it the last time I checked, and I doubt that IE7 will, either.

You shouldn't need it, anyway. Just make sure that the server sends back a text/xml or application/xml Content-Type header value.



try {
httpRequest = new ActiveXObject(XMLHTTPREQUEST_MS_PROGIDS[i]);

Normally I wouldn't recommend openly using exception handling, but it shouldn't be an issue on a private network. On the Web, use Microsoft's conditional compilation (a JScript feature) to expose it to JScript 5 or later.



myXmlHttpRequest.onreadystatechange = loginUser();

This is possibly your problem: you're calling this function, rather than assigning a reference to it to the onreadystatechange property.

Mike

henkedo
03-12-2007, 12:07 PM
I've figured it out now it works without any probs

Hello. I have same problem... can you please share the solution?

thanks
.henkedo