Link to home
Start Free TrialLog in
Avatar of lino_evolution
lino_evolutionFlag for Afghanistan

asked on

JQuery not getting called when Ajax is used

I am trying to call some JQuery functions from anchors that are passed through an AJAX method call.  These anchors do not exist on the page until they are called from a ajax method which then populates a div tag with the new anchors.  

The JQuery is not called.  Is this because the JQuery functions are on the client side and the anchors are created on the server side then passed to the client.

Is there anyway to get this to work?

the code attached is the anchor that is passed during the call to the ajax method.
<a href='communityDetails.aspx?mID=" & postID & "&action=bH&iframe=true&width=400&height=380' rel='prettyPhoto[iframes]'>" & Name & "</a>"

Open in new window

Avatar of leakim971
leakim971
Flag of Guadeloupe image

use live("click",function() instead click(function( or bind("click", function()

http://api.jquery.com/live/
Avatar of lino_evolution

ASKER

Thanks leakim971, but can you clarify a bit more please.

Do I place the live click function on the anchor?

or do I put this in the custom JQuery library?

and how do I bind that click event to the particular prettyphoto function?



ok, if you're using a plugin and you want to apply something on new link, just recall (or call) the function once you create the new link
so forget my previous answer
once you add the new link "recall" prettyphoto
recall?  can you elaborate on that?

how do i recall a function that is executed through an anchor? using rel='prettyPhoto[iframes]'
$.ajax({ ...., success:function(data) {
                 blabla to add the new links
                 blabla to add the new links
                 blabla to add the new links
                 blabla to add the new links
 
                 $("a[rel^='prettyPhoto']").prettyPhoto(..blablabla.); // here we "recall"
       },
);
I am creating and calling my AJAX method in a different way.  I think that is why I am confused.

on my HTML page I have a div tag; <div id="BlogLoader"></div>  

on

Page Load I call a javascript function that creates the XML Request Object and using the request to get the HTML code via a call to another page on the server.

function getCurrentBlogs()
{
         *create request object
        var userid = getQueryVariable('iUserID');
               request.open("get", "blog_data.aspx?data=g1&u=" + userid + "&anti-cache=" + new Date().getTime() , true);
            request.onreadystatechange = handleBlogs;
            request.send(null);
}

the function on the other end, at that blog_data page processes and returns HTML code to be displayed in the div tag, (which contains the anchors that calls pretty photo)

and sets the text to the DIV tag to the returned HTML

function handleBlogs()
{
      if(request.readyState == 1)
      {            
          $('#BlogLoader').html("<div style='padding-top: 100px; text-align:center;'><img src='/imgs/loading_icon.gif' /></div>");
      }
    if(request.readyState == 4){ //Finished loading the response
            $('#BlogLoader').html(request.responseText);        
      }      
      
}

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Brilliant! Thank you .. answered a bunch of other questions as well.