How to include javascript in jquery loaded content using $ .ajax

I want to load some HTML that includes some javascript using jQuery. I've tried using both load () and ajax (). HTML fits well into the DOM, but any script-tags seem to be filtered out. If I alert () the returned HTML scripts are included, but when I use html () or append () the scripts are missing.

Any ideas?

+2


source to share


2 answers


You should use $.getScript

to load and execute remote Javascript:

Loads and executes a local JavaScript file using an HTTP GET request.



Example:

$.getScript("test.js", function(){
  alert("Script loaded and executed.");
  $('#myDiv').load('some.html');
});

      

+3


source


try using:

$.get("url.php",{param1:'1',param2:'2'},function(result)){
    $('#somediv').html(result);
}

      



ps use the latest jQuery

0


source







All Articles