Hi,

I'm loading a page reloaded every x seconds is injected into the dom
(#reloaded). The page in question contains links of a certain class
(.loadNewPage). Clicking on a loadNewPage link will load another page
in another div (#edit). Since the links are the result of a page
loaded into the dom, I used livequery to bind their event.

Halas...

There's a "three click" problematic process (.loadNewPage links in
#reloaded)

1. first click does what's expected (the remote page is loaded
correctly and injuected into #edit)
2. second click loads the whole page itself into the  #edit div
3. third click doesn't load nothing, simply follows the link (no AJAX,
a plain HTTP request).

And this, no matter which link I click (it doesn't have to be three
times the same click). If I reload the whole page between two clicks,
it goes fine.

Now if you can figure out what's wrong, much respect...


jQuery code:

$(document).ready(function(){
    $("a.load").livequery('click', function(event) {
      var id = $(this).attr('id').substr(1);//the id starts with a
letter for compliancy
      $("div#edit").html('<img src=wait.jpg" />');
      $("div#edit").load("edit.php/id/" + id);
    return false;
    });
  });



  function load() {
    $("div#reloaded").load("reloaded.php", '', autorefresh);//
reloaded.php contains the links with class="loadNewPage"
  }

  function autorefresh() {
    setTimeout("load();", 4000);
  }

  $(document).ready(load);

Mark-up:


<div id="mainContent">

  <div id="reloaded"></div><!-- reloaded.php, the html injected here
contains the links: -->
  <div id="edit"></div><!-- edit.php, loaded when a link from
"reloaded" is clicked -->

</div>


:)

Reply via email to