/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Ajax + IE = Not working

I have an site that runs on Ajax. I always use Firefox as my browser, but when I tested my site with Internet Explorer 6, the Ajax didn’t work as expected. For some reason, the links that load with Ajax only work the first time. I don’t know why, but that’s what’s happening. Here is my HTML for the links:

[code=html]<div id=”leftmenu”>
<ul>
<li><a href=”index.php” onClick=”return requestPage(‘index.php’);”>Home</a></li>
<li><a href=”news.php” onClick=”return requestPage(‘news.php’);”>News</a></li>
<li><a href=”projects.php” onClick=”return requestPage(‘projects.php’);”>Projects</a></li>
</ul>
</div>[/code]

And here is the requestPage() function, where ajax.request is the request object:

[code]/*
* Requests a page and loads it using Ajax
*/
function requestPage(url)
{
var respose;
if (ajax.request == null)
{
return; // User does not want to use Ajax
}
ajax.method = ‘GET’;
if (url.match(/.*?.*/))
{
ajax.url = url + ‘&ajax=true’;
}
else
{
ajax.url = url + ‘?ajax=true’;
}
ajax.sendRequest();
ajax.request.onreadystatechange = function()
{
if (ajax.request.readyState !== 4)
{
document.getElementById(‘leftmenu’).style.display = ‘none’;
document.getElementById(‘content’).innerHTML = ‘Loading…’;
}
else if (ajax.request.readyState == 4)
{
response = ajax.request.responseText;
if (response)
{
document.getElementById(‘content’).innerHTML = response;
document.getElementById(‘leftmenu’).style.display = ”;
}
else // The server did not return anything
{
error(3);
return;
}
}
}
return false;
}[/code]

It works perfectly in FF and Opera (a little slow in Opera but that’s ok), but for some reason it only works the first time in IE. Anyone know what could be the problem? IE bug I’m guessing?

Thanks in advance!

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@netbuddyJul 23.2006 — change.. if (ajax.request.readyState !== 4) ..to.. if (ajax.request.readyState != 4)

what is.. error(3); all about? I suspect that you have not posted your entire script so we cant see if your making the ajax object correctly for MSIE.
Copy linkTweet thisAlerts:
@FatalErrorauthorJul 24.2006 — change.. if (ajax.request.readyState !== 4) ..to.. if (ajax.request.readyState != 4)[/quote]I was wondering about that...thanks.

what is.. error(3); all about?[/quote]error() is an error function I made that basically just redirects the user to an error page.

I suspect that you have not posted your entire script so we cant see if your making the ajax object correctly for MSIE.[/quote]I didn't think the rest of the code was relevant. I know for certain the object works, the problem is it only works [b]once[/b]. This code that I posted was the only thing that could have caused the problem.



Anyway, I found out what caused the problem...well...actually I didn't, I just put the requestPage() function inside the ajax object, and it seemed to work.
×

Success!

Help @FatalError spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...