...

View Full Version : AJAX looping issue



mikebarbaro
10-11-2010, 08:27 AM
I have the following code that changes the contents of a <div> once the ajax result is loaded. The problem is where I am trying to load in quote_feed.php it keeps reloading that section over and over again. I think it's because the loop continues to reload. Please help! I've been working for days on this and I think it should be an easy fix.


function insertReply() {
if(http.readyState == 4){
var response = http.responseText;
// else if login is ok show a message: "Site added+ site URL".
document.getElementById('insert_response').innerHTML = '<div width="400px" style="color:#FFF; padding:5px; background-color:#06C; border: #CCC 1px solid;">Posted! Tell your friends!</div>';

// THE BELOW 3 LINES HAS THE PROBLEM
document.getElementById('quote_feed').innerHTML=http.responseText;
http.open("GET", "quote_feed.php", true);
http.send(null);


}
}

tfburges
10-11-2010, 09:30 PM
You've definitely got it set up so that it gets stuck in a loop.

Do this instead:


function insertReply() {
http.open("GET", "quote_feed.php", true);
http.onreadystatechange = function() {
if (http.readyState == 4 && http.status == 200) {
document.getElementById('insert_response').innerHTML = '<div width="400px" style="color:#FFF; padding:5px; background-color:#06C; border: #CCC 1px solid;">Posted! Tell your friends!</div>';
document.getElementById('quote_feed').innerHTML = http.responseText;
}
}
http.send(null);
}

mikebarbaro
10-18-2010, 06:55 PM
thank you so much, worked perfectly!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum