0

I have jQuery ajax requesting a page that returns html with <script> tags inside that html, I have the dataType option set to "html" so that I get the JS inside the <script> tags executed, this works fine but the problem that it takes the browser from 2-3 seconds to evaluate the returned JS after the ajax response, why is the delay? it causes JS errors for users in hurry who try to click buttons immediately after the ajax response.

Please help.

Thanks.

2
  • Is the javascript in your HTML directly included in a SCRIPT element, or does it use SCRIPT SRC=""? Commented Jun 1, 2009 at 20:00
  • The retuend HTML contains both, ah, that could be the problem then, jQuery ajax waits for <script src> to load then executes the JS in the <script>, right? Commented Jun 1, 2009 at 20:26

2 Answers 2

1

Without seeing the code, its impossible to say what is causing the execution delay. However, you can profile the returned JS code yourself using Firebug's profiler.

console.profile("Returned JS");
//your AJAX call
console.profileEnd();

This will output an execution profile to Firebug's console, and you'll be able to see where the execution bottleneck is occurring.

http://getfirebug.com/console.html

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

Comments

0

When you add HTML to an element using jQuery, first jQuery searches for any SCRIPT elements in the HTML. If the HTML contains SCRIPT SRC="", then jquery attempts to asynchronously fetch the javascript file. This could be causing your delay.

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.