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?

1
  • what version of jQuery are you using? In 1.2+, the evalScripts() method should be done automatically Commented Oct 6, 2009 at 14:29

2 Answers 2

3

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');
});
Sign up to request clarification or add additional context in comments.

Comments

0

try using:

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

p.s. please use the latest jquery version

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.