Reputation: 31
this is my first post here. I've been writing a chat script for a while now, but I've come across an issue. When I use my original code, the browser freezes because it's still trying to load. I have tried almost everything. I'm a bit stumped because I had an idea to clone the function to go back and forth and it STILL won't work. Here is a snippet of what I'm working with.
function jumpanti(){
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari, SeaMonkey
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("chatContent").innerHTML = xmlhttp.responseText;
antifreeze();
}
}
xmlhttp.open("GET", "innerchat.php", false);
xmlhttp.send();
twemoji.parse(document.body);
// Twemoji parse
}
function antifreeze(){
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari, SeaMonkey
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("chatContent").innerHTML = xmlhttp.responseText;
jumpanti();
}
}
xmlhttp.open("GET", "innerchat.php", false);
xmlhttp.send();
twemoji.parse(document.body);
// Twemoji parse
}
I've tried and it still won't work. What I want my code to do is to try and load the chat until it gets a 200 response and then loop. Does anyone have any solutions to this using only XHR?
Upvotes: 1
Views: 235
Reputation: 31
I fixed the problem. The issue was I didn't have asynchronous XML turned on inside the function. It froze the page a lot. I changed xmlhttp.open("GET", "innerchat.php", false);
to xmlhttp.open("GET", "innerchat.php", true);
Upvotes: 2