Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3316466
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:28:21+00:00 2026-05-17T22:28:21+00:00

My site was using jquery.load() to do navigation on a big chunk of the

  • 0

My site was using jquery.load() to do navigation on a big chunk of the page. I really appreciate the ability to only include only a particular part of the loaded content, here the div with id=”content”:

$(frame_selector).load(url +" #content", function(response, status, xhr) {...});

But now I need to be able to run scripts that are part of the pages being loaded dynamically. Jquery.load() strips out these scripts, but jquery.ajax() doesn’t. So I duplicated the partial-content functionality of jquery.load in an ajax call as such:

$.ajax({
  url: url,
  dataType: 'html', 
  success: function(data, textStatus, XMLHttpRequest) {
      // Only include the response within the #content id element.
      $(frame_selector).html( jQuery("<div>")
            .append(data)
            .find("#content")
      );
  }
});

The problem is that the scripts which are being dynamically loaded from the ajax call aren’t running reliably. Sometimes they don’t seem to have any effect, perhaps because they’re running too early. The scripts are just doing DOM manipulation in jquery — not relying on images or flash or anything that’s not supposed to be loaded yet. To keep from getting stuck I have this hideous hack to get things working. Instead of the AJAX-loaded script just using:

$(document).ready( function() {...} );  // unreliable

I delay the script 200ms before running:

$(document).ready( window.setTimeout( function() {...}, 200 )); // HATE THIS

Anybody know how I can make this work reliably without hard-coding a delay? I’m guessing it’s a race condition between the <script> and my logic to load #content into a new div, but I’m not sure what to do about it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:28:22+00:00Added an answer on May 17, 2026 at 10:28 pm

    I assume the scripts are doing manipulation upon the DOM elements you’re adding through AJAX.

    jQuery has an isReady property that it sets once the ready event has been triggered on the page.

    Any subsequent calls to jQuery.ready(...) will first check this isReady flag. If the flag is set to true, it will call the handler immediately. You can see why this would cause problems in your code.

    One option would be to load the response into a jQuery fragment and parse out all of the <script /> tags for execution later.

    var ajaxResponse = $(html);
    var scripts = ajaxResponse.find('script');
    
    // Move your scripts into a new element
    var tempScripts = $().append(scripts);
    
    // Append your content, followed by your script tags
    $(document).append(ajaxResponse);
    $(document).append(tempScripts);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to load a new page (a new div actually using jQuery
I'm developing a site using jQuery, and jQuery UI tabs. For some reason, my
I've rewritten my family web site using JavaScript (JQuery) making Ajax calls to PHP
For our site, Im using a lot of jQuery - right now Im looking
I'm trying to pullout some info from an external site using jQuery and Adobe
I'm trying to load all my website pages using jQuery .load method so, thats
I'm trying to build a site that runs without refreshes, using Jquery and PHP
I am using jQuery load() function to load some pages into container. Here is
I've got a site with endlessly sliding images using jquery's setIntervall() function. When calling
I am coding a gallery section for my personal site in JS, using jQuery.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.