I was wondering if there is a way to execute script within a ajax dynamically loaded content. I've searched the web and this forum also an find a lot of answers, like
[Running scripts in an ajax-loaded page fragment [1]: Running scripts in an ajax-loaded page fragment [1]
But none of this seems to work fine for me. I'm not experienced as the author of the quoted post, so maybe we can find a solution more simple and quite for everyone.
For now i've implemented a tricky turnaround that smell to much of an hard-coded solution that is:
//EXECUTE AJAX REQUEST LET'S SAY SUCCESSFULLY, $ajax([..]) //THEN .ajaxSuccess(function(){ // LOCATE ANY OBJECT PRE-MARKED WITH A SPECIFIC CLASS $(".script_target").each(function() { //DO SOMETHING BASED ON A PRESET ATTRIBUTE OF THIS SPECIFIC ELEMENT //EXAMPLE: <div class=".script_target" transition="drop_down">...</div> //WILL FIRE A SCRIPT RELATED TO drop_down CASE. }); });
I know this is an ugly solution but i didn't came up with nothing better than this. Can you help to improve this method? Maybe there's a way to let the browser fire script within the loaded page automatically?
PS. I'm not going to use the eval() method if it's not the last solution, cause both security leak and global slowdown, AND be aware that the script launched need to modify objects loaded in the same fragment of the script.
Thanks in advance.