Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-11-2010, 08:27 AM   PM User | #1
mikebarbaro
New to the CF scene

 
Join Date: Oct 2010
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
mikebarbaro is an unknown quantity at this point
Question AJAX looping issue

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.

Code:
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);


}
}
mikebarbaro is offline   Reply With Quote
Old 10-11-2010, 09:30 PM   PM User | #2
tfburges
Regular Coder

 
Join Date: May 2009
Posts: 425
Thanks: 3
Thanked 62 Times in 61 Posts
tfburges is an unknown quantity at this point
You've definitely got it set up so that it gets stuck in a loop.

Do this instead:
PHP Code:
function insertReply() {
    
http.open("GET""quote_feed.php"true);
    
http.onreadystatechange = function() {
        if (
http.readyState == && 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);

tfburges is offline   Reply With Quote
Users who have thanked tfburges for this post:
mikebarbaro (10-18-2010)
Old 10-18-2010, 06:55 PM   PM User | #3
mikebarbaro
New to the CF scene

 
Join Date: Oct 2010
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
mikebarbaro is an unknown quantity at this point
thank you so much, worked perfectly!
mikebarbaro is offline   Reply With Quote
Reply

Bookmarks

Tags
ajax, javascript, loop, looping

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:16 PM.


Advertisement
Log in to turn off these ads.