tags:

views:

41

answers:

2
  <a class="source" href="jquery-lead.php?source=<?=$src;?>">3</a>

<script type="text/javascript">
    $("a.source").live('click', function() { 
        $("#results").load(this.href, { page: $(this).text() });
      return false;
    });
    $("a.source:first").click()
</script> 

I am able to pass $src variable to my php script, but I also want to pass whatever is in the tag. In this case "3", this is going to be a pagination..

A: 
$(this).text();
simplemotives
+1  A: 

Updated for comments - You can do it like this:

$(function() {
  $("a.source").live('click', function() { 
    $("#results").load(this.href, { page: $(this).text() });
    return false;
  });
  $("a.source:first").click();
});

This uses .load(url, data), in your php the page variable will now be available...or whatever you want it called, just rename appropriately.

Nick Craver
its sends page as a POST and not GET, what are the differences? Should I try to stick with GET on both variables or it makes no difference?
vick
@vick - I'd have a read here for the differences: http://stackoverflow.com/questions/46585/when-do-you-use-post-and-when-do-you-use-get As for the other...up to you, what does that `source` variable look like?
Nick Craver
ok thanks nick.I am also wondering is there a way to automatically call the first link in the paginator?<a class="source" href="jquery-lead.php?src=<?=$src;?>">1</a></div>
vick
@vick - `$("a.source:first").click()` would execute the handler for it.
Nick Craver
Nick: What am I doing wrong, check above
vick
@vick - You have to tell me what the error/behavior is to answer that...also I would go accept answers on your questions, with 0 chance on reward, there's not much motivation for anyone to help...
Nick Craver
Nick: Its not loading the first page, I still have to click on the first link to get something to load.
vick
@vick - Make sure you put that code **after** the code above, you want the click handler attached before triggering the event.
Nick Craver
Look at the new code above, that is how it is now...still not calling the first link :(
vick
@vick - Ah you're missing a `document.ready` wrapper, so the code doesn't execute until the `<a>` exists to find. Look at the updated answer above for how to wrap it so it'll execute on `document.ready`.
Nick Craver
thanks works fine now!!
vick