SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard
    Join Date
    Jan 2005
    Location
    blahblahblah
    Posts
    1,447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    livequery question

    Hi,

    Please consider the code below:

    Code:
    $(document).ready(function(){
        $("div#display").load("display.php");
    });
    
    $(document).ready(function(){
        $("a.test").livequery("click",function(event){
          var id = $(this).attr('id').substr(1);
          $("div#status").html('<img name="wait" src="wait.jpg" />');
          $("div#status").load("delete.php?id=" + id);
          $("div#display").load("display.php");
          return false;
        });
    });
    display.php is loaded with the document and injected into the dom (the first time the page is loaded, that is). Then when a link with class .test is clicked, a deletion process is triggered (delete.php, which outputs a process status), and the display.php page should be reloaded and re-injected into the dom, with updated results.

    The reload of display.php after a .test click is quirky. Sometimes it works, sometimes it doesn't.

    Any idea why?

    Regards,

    -jj.

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Keep in mind load() is an asynchronous request. So the http request to display.php is sent well before the request to delete.php has finished executing. I smell race conditions and concurrency issues.

    Now you have two serverside scripts racing, one trying to update the database(im assuming) and the other trying to read. Maybe the winner isn't what you expect. Try putting sleep(1) in display.php at the beggining of the file. If that fixes the problem, well now you know you need to address it more appropriately.

    You could have issues with sessions and files as well.

  3. #3
    SitePoint Wizard
    Join Date
    Jan 2005
    Location
    blahblahblah
    Posts
    1,447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You perfectly nailed down the issue.

    You got to be the reason why a rep system should be back on these premises.

    Thank you once again, you're helpful in many different fields, and always efficient.

    -jj.


Bookmarks

Posting Permissions

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