0

I load a template from an ajax call(and I put that content inside a div using .html()). This template has and some divs.

The problem is that I receive the correct JS from that call, but it seems that .html() does not update the <script>. I have:

<div id="val">
   <script>....</script>
</div>

when I do: $('#val').html(contentFromAJAX), the JS is not loaded correctly. How can i do?

EDIT: with "not loaded correctly", I mean that the previous <script> inside that div remain there, .html() seems do not change it.

5
  • what is not working are you sure you have something in the variable? jsfiddle.net/ue44U do you want to execute the returned content as JavaScript? or add some JavaScript to the DOM? Commented Nov 2, 2011 at 10:12
  • im confused... are you recieving html or js from the ajax call?? for js try text() instead of html() Commented Nov 2, 2011 at 10:12
  • @ZolaKt, I'm receiving a template....this template has <script> and <div> Commented Nov 2, 2011 at 10:13
  • @gordatron: i dont think that is important, even if the variable is empty it should replace the old html Commented Nov 2, 2011 at 10:13
  • @Dail: what kind of template? there are many templates... post the sample return from the call Commented Nov 2, 2011 at 10:14

1 Answer 1

0

Set the dataType of your ajax call: dataType: "script"

Or use the jQuery.getScript()

Sign up to request clarification or add additional context in comments.

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.