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 6671913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:26:47+00:00 2026-05-26T03:26:47+00:00

I am loading another page into an el via XHR . The loaded page

  • 0

I am loading another page into an el via XHR. The loaded page has js on it that throws an error and fails unless the required dom element is loaded on the page. As it’s XHR .ready et. al. won’t work.

I have it working with a 500 ms timeout, but that’s not OK; there has to be a better way. With timeout, the dom el doesn’t always load and the page fails.

There is a table hard-coded on the page with an id. The script in the page is a jquery plugin (datatables) and won’t init unless the table is loaded.

I’ve thought about having a function that inits the datatables stuff and calling that repeatedly while $('#tableID') is null but not sure that’s correct.

<div id="contactQueue">
<table cellpadding="0" cellspacing="0" border="0" class="display" id="contactsQueueTable">
    <thead>
        <tr>
            <th class="" rowspan="1" colspan="1" style="width: 185px; ">Contact Name</th>
            <th class="" rowspan="1" colspan="1" style="width: 148px; ">Bus. Name</th>
            <th class="" rowspan="1" colspan="1" style="width: 116px; ">Is Client</th>
            <th class="" rowspan="1" colspan="1" style="width: 165px; ">Remove</th>
        </tr>
    </thead>
    <tbody>
    </tbody>
</table>
</div>
<?php echo form_open('',array('id'=>'step2form','name'=>'step2form'));?>
<input type="hidden" name="clientID" value="<?php echo $clientID; ?>">
<?php echo form_close();?>


<script type="text/javascript" charset="utf-8">
console.log(jq('#currentContactsTable'))
while(jq('#currentContactsTable').html()==null){
    initXHRPage();
    console.log(jq('#currentContactsTable')+' not ready');
}
function initXHRPage(){
    //init tables stuffs
}

EDIT;

The issue was something else, kinda. The script for Datatables is being loaded via getScript(). The element was being loaded normally, but initDatatables() was firing before getScript() was done loading, not before the el was loaded.

The solution was to call the initDatatables() function in the getScript() success callback:

<script type="text/javascript" charset="utf-8">
var jsf = '/js/jquery.dataTables.js';
jq.getScript(jsf, function(data, textStatus){
    console.log('Loaded:'+jsf+" From: <?php echo $this->uri->uri_string(); ?>");
    initDatatable();
});
</script>
  • 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-26T03:26:48+00:00Added an answer on May 26, 2026 at 3:26 am

    This is what I came up with. Thx to respondents for help.

    initPage();
    
    function initPage(){
        if(jq('#currentContactsTable').length==1){
                initDatatable();
        }else{
                window.setTimeout(function(){
                        initPage();
                },250);
        }
    }
    
    function initDatatable(){
        jq('#currentContactsTable').dataTable( {
                //REST OF DATATABLE STUFF...
    

    It may not be super pretty as it still is relying on a timeout, but at least this timeout it a bit more robust…


    ^^^^ BZZZZZZZZZ

    The issue was something else, kinda. The script for Datatables is being loaded via getScript(). The element was being loaded normally, but initDatatables() was firing before getScript() was done loading, not before the el was loaded.

    The solution was to call the initDatatables() function in the getScript() success callback:

    <script type="text/javascript" charset="utf-8">
    var jsf = '/js/jquery.dataTables.js';
    jq.getScript(jsf, function(data, textStatus){
        console.log('Loaded:'+jsf+" From: <?php echo $this->uri->uri_string(); ?>");
        initDatatable();
    });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have page loading, via AJAX a PHP page into a div. In turn,
While my page is loading content via XHR, if the user clicks the stop
I have the following html code: (that gets loaded via ajax into a div)
I have a AS3 swf [1] that is loading another AS2 swf [2] which
Upon loading into a C++ program a Prolog program that contains the command 'send'
I am trying to get another page to call into a div on a
index.php has this jquery code which loads notifications.inc.php into a div on the page
I'm using the Jquery load function $('#result').load('test.php'); to load a page into another page
I have a page that has 5 sections. Each section takes about 1 second
Loading images into Flex (size < 100kb) causes IE7 memory increase by a megabyte

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.