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>
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;
}
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!