How to use jQuery .load so that it pulls in an element after all scripts have finished running?

Mike

I am currently using datatables.js to provide a directory on a WordPress site: example.com/directory.

I added the ability to filter the directory using a querystring so I can create links that when loaded show a subset of the directory: example.com/directory/?search=query.

Here is the code I am using on the directory page:

<script charset="utf-8" type="text/javascript">// <![CDATA[
jQuery(document).ready(function() {
    jQuery.urlParam = function(name){
        var results = new RegExp('[\\?&#038;]' + name + '=([^&#]*)').exec(window.location.href);
        if (!results)
        {
            return '';
        }
        return unescape(results[1]) || '';
    }

    jQuery('#directory').dataTable( {
         "sPaginationType": "full_numbers",
         "aLengthMenu": [[15, 30, -1], [15, 30, "All"]],
         "iDisplayLength" : 15,
         "oSearch": {"sSearch": jQuery.urlParam('search')}
         }).rowGrouping()

    jQuery('div.dataTables_filter input').focus();
});
// ]]></script>

And for a page to that includes a subset of the directory: example.com/departmentpage.

<script charset="utf-8" type="text/javascript">// <![CDATA[
jQuery(document).ready(function() {
    jQuery("#result").load("http://example.com/directory/?search=departmentname #directory > *");
});
// ]]></script>
<div id="result"></div>

The .load function works but it pulls in the entire raw table, not the table as it normally looks on the main directory page. My assumption is that the .load function is pulling the #directory before the scripts run.

Is there a way to make .load wait until the scripts on the included page have run before it pulls the content into the includer page?

tr3online

You are pulling #directory > * with .load(). If the script required to render the HTML you are pulling in is not contained in your .load() statement, nothing will happen. You will only be pulling raw HTML in.

You need to either include the script, or pull in the HTML via a different method and re-run the javascript needed to convert the table to its desired affect.

Upon initial inspection of the plugin you are using, I would recommend trying to use the sAjaxSource method to grab your data.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I run code after all threads have finished running?

From Dev

How to load an element to jQuery if all i have is an event

From Dev

Executing code after all requests have finished (Facebook SDK)

From Dev

use wait to wait after all process finished but strange output

From Dev

How to wait until all tasks are finished before running code

From Dev

how to use drawImage after load all images in array

From Dev

How to check if all async operations have finished using AngularJS?

From Dev

How to Quit program when all the thread have been finished?

From Dev

How to change anchor text when a method has finished running in jQuery?

From Dev

How to wrap all elements inside a div after a certain element? (JQuery)

From Dev

Python, multiple scripts, each with multiple threads running, how can one script determine when threads in other scripts are finished?

From Dev

jQuery trigger on element that is added after page load

From Dev

How to use jQuery fadeIn with element created using .after?

From Dev

How to block all the events when the animation is not yet finished in jquery

From Dev

Jquery: How to time an action to start after a different action has finished

From Dev

jquery running after all javascript has ended

From Dev

Use the jQuery load() function to get the grandparent of an element

From Dev

Running dynamically loaded jQuery after dynamically loaded content has finished loading

From Dev

How to have a block element display after all inline elements in a row without breaking them into separate lines

From Dev

how to load all scripts and links from one html file?

From Dev

How to use jQuery to load codepress

From Dev

How to use the options of jQuery .load

From Dev

Sidekiq not deallocating memory after workers have finished

From Dev

Call function after ajax calls have finished

From Dev

Call function after ajax calls have finished

From Dev

How should I make sure that the onCreate(View/Dialog) has finished running, so everything is properly initialised?

From Dev

how to deselect all element in jquery?

From Dev

how to deselect all element in jquery?

From Dev

Load a new level after all coins have been collected

Related Related

  1. 1

    How do I run code after all threads have finished running?

  2. 2

    How to load an element to jQuery if all i have is an event

  3. 3

    Executing code after all requests have finished (Facebook SDK)

  4. 4

    use wait to wait after all process finished but strange output

  5. 5

    How to wait until all tasks are finished before running code

  6. 6

    how to use drawImage after load all images in array

  7. 7

    How to check if all async operations have finished using AngularJS?

  8. 8

    How to Quit program when all the thread have been finished?

  9. 9

    How to change anchor text when a method has finished running in jQuery?

  10. 10

    How to wrap all elements inside a div after a certain element? (JQuery)

  11. 11

    Python, multiple scripts, each with multiple threads running, how can one script determine when threads in other scripts are finished?

  12. 12

    jQuery trigger on element that is added after page load

  13. 13

    How to use jQuery fadeIn with element created using .after?

  14. 14

    How to block all the events when the animation is not yet finished in jquery

  15. 15

    Jquery: How to time an action to start after a different action has finished

  16. 16

    jquery running after all javascript has ended

  17. 17

    Use the jQuery load() function to get the grandparent of an element

  18. 18

    Running dynamically loaded jQuery after dynamically loaded content has finished loading

  19. 19

    How to have a block element display after all inline elements in a row without breaking them into separate lines

  20. 20

    how to load all scripts and links from one html file?

  21. 21

    How to use jQuery to load codepress

  22. 22

    How to use the options of jQuery .load

  23. 23

    Sidekiq not deallocating memory after workers have finished

  24. 24

    Call function after ajax calls have finished

  25. 25

    Call function after ajax calls have finished

  26. 26

    How should I make sure that the onCreate(View/Dialog) has finished running, so everything is properly initialised?

  27. 27

    how to deselect all element in jquery?

  28. 28

    how to deselect all element in jquery?

  29. 29

    Load a new level after all coins have been collected

HotTag

Archive