I have Problems after loading a whole new page via Ajax to get all inline JS and CSS executed. The result of this call is a whole new page including , i want to replace with current content. Does JQuery provide functionality to execute all scripts after success of an Ajax Call? My first idea was to select all script tags from result and append it to the body. Second idea was to selecet all script tags and execute their contents with eval(). Thx for helping..
1 Answer
When you call .html() in jQuery to insert the returned HTML into the page, all inline scripts will be executed. For example: http://jsfiddle.net/Paulpro/LX58E/ Or:
var html = '<script type="text/javascript"> alert(\'Hi\'); <\/script>';
// Execute the script twice
$('body').html(html+html);