Tuesday, 15 September 2015

Bind jQuery function after ajax call -



Bind jQuery function after ajax call -

ok, i've been trying work few days now. have thumbnail scroller , works fine when window loaded provide code below. after ajax phone call not.

this function loaded initially.

(function($){ window.onload=function(){ $("#ts2").thumbnailscroller({ scrollertype:"clickbuttons", scrollerorientation:"horizontal", scrollspeed:2, scrolleasing:"easeoutcirc", scrolleasingamount:800, acceleration:4, scrollspeed:800, noscrollcenterspace:10, autoscrolling:0, autoscrollingspeed:2000, autoscrollingeasing:"easeinoutquad", autoscrollingdelay:500 }); } })(jquery);

i tried adding part below in ajax function phone call still doesn't work.

$("#ts2").thumbnailscroller({ scrollertype:"clickbuttons", scrollerorientation:"horizontal", scrollspeed:2, scrolleasing:"easeoutcirc", scrolleasingamount:800, acceleration:4, scrollspeed:800, noscrollcenterspace:10, autoscrolling:0, autoscrollingspeed:2000, autoscrollingeasing:"easeinoutquad", autoscrollingdelay:500 }); }

how reinitialize or there way utilize on? problem id/element not loaded until ajax phone call done, need reattach thumbnailscoller function. btw click ajax phone call uses .on placing function in there doesn't work. help welcomed.

edit: here ajax call.

$.ajax({ type: "post", url: "/ajax.php", data: {"pho_id": pho_id, "alb_id": alb_id}, success: function(response){ $("#phoajax").html(response); $("#ts2").thumbnailscroller({ scrollertype:"clickbuttons", scrollerorientation:"horizontal", scrollspeed:2, scrolleasing:"easeoutcirc", scrolleasingamount:800, acceleration:4, scrollspeed:800, noscrollcenterspace:10, autoscrolling:0, autoscrollingspeed:2000, autoscrollingeasing:"easeinoutquad", autoscrollingdelay:500 }); pslide(alb_id); } })

you have phone call in callback function of ajax call, not after it:

$.post("some_url", {var: var1 .... etc}, function(data){ //the same $.ajax, $.get //here ! });

the callback function executed after ajax phone call done, if modified or added dom elements ajax phone call need apply jquery functions after modification.

jquery

No comments:

Post a Comment