jQuery slider doesn't show if called in a div using Ajax ( creating a xmlhttprequest, onreadystatechange etc.) -
i working on college project in ajax , jsp, using jquery snippets available on internet (galleria, dropdown menus etc.), quite confident in javascript, knowledge of jquery extremely limited.
in index page, call main content div using ajax methods ( not jquery ajax, complete javascript, onreadystatechange() , responsetext). have jquery image slider , jquery menu in content. these don't work after ajax callback. have read problem need re-bind events after callback don't understand how to.
to re-bind events after callback
$.ajax({ type: 'post', //default here 'get' url: '/path/to/my/file.jsp data: mydatavariable // alternatively can use data: { $("jqueryselector").val)(); } success: function(data){ if(data){ $("body").on("bind", "elementidorclass", function(){ //these functions bound on callback. stuff }); $("someelement").html(data); //place data returned inside of containaer named 'someelement' } } });
pretty straight forward. if our ajax request successful, return data wrapped in json object. test ensure data received not empty, bind our functions element 'elementidorclass'. then, load our data 'someelement'.
Comments
Post a Comment