Jump to content

AJAX erroring in IE when i run a function, works fine in FF


Mattyspatty

Recommended Posts

Hey i hope i can get some help on this one its really bugging me,

i have a page that has links on and when you click the links a different page is included in the body of the page, all my links are fine except 1! it only stops working in IE, in FF its fine. All other links i have tried work perfectly fine in both IE and FF buts its just this 1 link that messes up IE!

[code]
<td height="1" align="center"><a onClick="include('home')" href="#">Home</a></td>
<td height="1" align="center"><a onClick="include('military')" href="#">Military</a></td>
<td height="1" align="center"><a onClick="include('construction')" href="#">Construction</a></td>
<td height="1" align="center"><a onClick="include('inbox')" href="#">Messages</a></td> <!--Its this link that errors-->
<td height="1" align="center"><a onClick="logout()" href="#">Logout</a></td>[/code]
i dont have a clue whats up with it, i guess its just IE is being a (*&$^ about it


[code]
function createRequestObject(){
var request_o;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_o = new ActiveXObject("Microsoft.XMLHTTP");
}else{
request_o = new XMLHttpRequest();
}
return request_o;
}
var page = createRequestObject();
var stat = createRequestObject();

function include(myPage){
statsbar_update();
//alert(myPage);
myForm = code_body;
page.open('get', 'includes.php?page=' + myPage);
page.onreadystatechange = handleInclude;
page.send(null);
}
function handleInclude(){
switch(page.readyState) {
case 4:
var response = page.responseText;
document.getElementById('include_area').innerHTML = response;
break;

default:
document.getElementById('include_area').innerHTML = "Querying, Please Wait...";
page.onreadystatechange = handleInclude;
}
}

function statsbar_update() {
stat.open('get', 'statsbar.php');
stat.onreadystatechange = handleStatsbar;
stat.send(null);
}
function handleStatsbar() {
switch(stat.readyState) {
case 4:
var response = stat.responseText;
document.getElementById('statsbar_area').innerHTML = response;
break;

default:
document.getElementById('statsbar_area').innerHTML = "Querying, Please Wait...";
stat.onreadystatechange = handleStatsbar;
}
}
[/code]
(optimisation comments appreciated;))


thanks in advance, Matty
I know when I get that error it usaly means that there is an issue with the XMLHTTP instance

Try this createRequestObject function (by ober)

[code]
function createRequestObject() {
    if (window.XMLHttpRequest) { // Mozilla, Safari, Opera...
        var xmlhttp = new XMLHttpRequest();
        if (xmlhttp.overrideMimeType)
xmlhttp.overrideMimeType('text/xml');
    }
else if (window.ActiveXObject) { // IE
        try {
            var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }

    if (!xmlhttp) {
        alert('Giving up :( Cannot create an XMLHTTP instance');
        return false;
    }
return xmlhttp;
}[/code]

Also, have you tried looking in FF's javascript consule?

Tom
hmm that didnt seem to work :(

i had a look at the FF JSconsole and i got an error about document.getElementById(). i refreshed the js file and now FF shows no error. i did notice this however:


line 26: document.getElementById('include_area').innerHTML = response;
line 27: break;

maybe its "document.getElementById('include_area')" erroring?  i have used <div id="include_area"></div> but i dont see whats wrong with that!
no sorry, i am using my local computer to create this page and i dont want to give access to random people!

i cant understand this problem, its only 1 link thats not working it makes no sense to me whatsoever :( 
thanks, matty
eh... I've run into that error before.  It's an absolute whore to troubleshoot.  IE sucks for this kinda stuff.

The only thing I can suggest is to throw more alerts in there to try and pop the error out into the open.

I've also had trouble in the past when 2 events try to use an object at the same time.  You might try creating more than one object instance and using a different object for each link.
[quote author=ober link=topic=113898.msg463651#msg463651 date=1162826953]
eh... I've run into that error before.  It's an absolute whore to troubleshoot.  IE sucks [s]for this kinda stuff.[/s][/quote]
ye its really annoying.. and, im not amazing at javascript but ill have a good go at alerting everything to find the problem, the new object instance idea sounds hopeful too.

thanks for your input, ill let you know if i have any more problems.
Matty
ok i have found out what was causing the error
[code]document.getElementById('include_area').innerHTML = response;[/code] will not run, it gets upto that line and errors when i click my problem link.

[code]document.getElementById('include_area').innerHTML = "test";[/code] the above code worked fine!!, i can only assume it is the page i am including causing a problem, i took a wild last hope attempt at trying anything just to see if it works an i almost had a heart attack! i have a FORM on the page i was including, i deleted that and all was fine and dandy!!! ill be able to sleep tonight ;)

its just one of those things i guess...
thanks for your input guys much appreciated :)
Matty
  • 6 months later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.