I've got this chat system on one of my pages which uses ajax to auto update itself every 10 seconds. I also have a normal html form. The ajax request sends for a file called chatAjax.php
and the form sends data to process.php
If the user submits the form before the timer is up the system works normally. However for some reason if the user takes a while to enter the data the data gets sent and then the user lands on chatAjax.php
instead of going back to the main page. I have no clue what is going on and process.php
has no references to chatAjax.php
. So why do they end up on chatAjax.php
?
Here is the ajax script:
function refresh(){
var ajaxRequest;
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something w开发者_运维百科ent wrong
alert("Your browser broke!");
return false;
}
}
}
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
document.getElementById("Chats").innerHTML= ajaxRequest.responseText;
}
}
ajaxRequest.open("POST", "chatAjax.php", true);
ajaxRequest.send(null);
setTimeout("refresh()",10000);
}
if you want a further look just go to http://www.cogtek.co.cc/community.php (thats the main page I was talking about)
I figured out the problem.
In my process.php script I would record what page I came from and then return to that page. It seems as though the ajax script overwrites this and the script would make it go to the wrong page. I have now set the part of the process.php script to now only go to community.php.
精彩评论