Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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);
    
    
    }
    }

  • #2
    Regular Coder
    Join Date
    May 2009
    Posts
    425
    Thanks
    3
    Thanked 62 Times in 61 Posts
    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);


  • Users who have thanked tfburges for this post:

    mikebarbaro (10-18-2010)

  • #3
    New to the CF scene
    Join Date
    Oct 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    thank you so much, worked perfectly!


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •