[SOLVED] AJAX » No repeat -- only working once
Posted: Fri Jan 18, 2008 2:13 pm
Hello, world!
I have some AJAX issues. I whiped up a quick, basic ajax connection. It works fine, unless I try it again. To get it to work again, I have to close the tab, and open the page up again in a new one.
When you click the button/link, it says "loading", until it is finished, and then the new stuff comes up. But, if you click it a second time, it says loading forever, and never opens the new stuff. The stuff is below:
I have experienced this problem with all of the other AJAX I've done. Why is this and how does one fix it? Has anyone else had this problem?
Thanks, world!
I have some AJAX issues. I whiped up a quick, basic ajax connection. It works fine, unless I try it again. To get it to work again, I have to close the tab, and open the page up again in a new one.
When you click the button/link, it says "loading", until it is finished, and then the new stuff comes up. But, if you click it a second time, it says loading forever, and never opens the new stuff. The stuff is below:
Code: Select all
function getAJAX(){// get AJAX
var ajax = false;
try {
ajax = new XMLHttpRequest();
}catch (e){
try {
ajax = new ActiveXObject('Msxml2.XMLHTTP');
}catch (e){
ajax = new ActiveXObject('Microsoft.XMLHTTP');
}
}
return ajax;
}
function Switch(url){// change Content
if (getAJAX()){//if ajax returns true
var doc = document.getElementById('CONTENT');// set var for doc content
doc.innerHTML = 'Loading...';
var ajx = getAJAX();
ajx.open('GET', 'php/page.php?p='+url, true);
ajx.send(null);
var y = 'window.location="?p='+url+'";';
var q = setTimeout(y, 30000);
ajx.onreadystatechange = function (){
clearTimeout(q);
if (ajx.readyState==4){
doc.innerHTML = ajx.responseText;
}
}
}else{//but if not, just goto that url
window.location = '?p='+url;
}
}Thanks, world!