views:

42

answers:

2

I want to load some HTML which include a bit of javascript, using jQuery. I've tried using both load() and ajax(). The HTML is inserted nicely into the DOM, but any script-tags seems to be filtered out. If I alert() the returned HTML, the scripts are included, but when i use html() or append(), the scripts are missing.

Any ideas?

+3  A: 

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');
});
karim79
A: 

try using:

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

p.s. please use the latest jquery version

jerjer