views:

79

answers:

3

hi i'm building something like a posts gallery and i want to do the following: 1. have thumbnail for each post 2. when a thumbnail is clicked, i want the new post to be loaded at a div at the top of the page w/o the posts gallery changing. to do that i want to pass the id of the clicked-on post to that div and then run the query_string there.

i got my thumbnail click function:

$(".thumb").click(function(){
     myLink=$(this).attr('href');
// get the post id into pID by finding p= and then extracting the next char after = from the link
        var t = myLink.indexOf("p=");
        var l = myLink.length;
        var pID = myLink.substring(t+2,l);
        $("#target").post('/?page_id=9', { postID: pID } );       
        $("#target").load("/?page_id=9");

        return false;
});

My problem is: $.post doesn't work. i've tried it with the $.ajax syntax too, and it still doesn't work. (it seems like the jQuery is aborted midway, as any alerts i put in the post or ajax callback functions are being ignored).

Please help...

A: 

ok, i got that i can't call .post with a selctor, so the line with the .post function should be $.post('/?page_id=9', { postID: pID } );

so now it does run the code, but it does nothing... nothing is posted to the specified url.

shiri
A: 

Have you tried using admin-ajax. Wordpress has a specific model for its ajax calls that takes care of security and other stuff. Check out the codex for admin-ajax

Pragati Sureka
A: 

When working with jQuery and Wordpress, jQuery needs to be loaded and coded in a certain way to avoid conflicts. 5 Tips For Using jQuery with WordPress by Eric Martin provides a good explanation.

shipshape