I am loading a function into a div using AJAX but I can't load in the scripts I need to run in the function.

How do I load scripts into an AJAX div?

My Javascript

(function($) {
$(document).on( 'click', 'a.mylink', function( event ) {
url: testing.ajax_url,
    data : {
    action : 'diplay_user_table'
success : function( response ) {
    jQuery('#user_reponse').html( response );



 add_action( 'wp_enqueue_scripts', 'ajax_test_enqueue_scripts' );
 function ajax_test_enqueue_scripts() {
 wp_enqueue_script( 'test', plugins_url( 'test.js', __FILE__ ),    
 array('jquery'), '1.0', true );
 wp_localize_script( 'test', 'testing', array(
'ajax_url' => admin_url( 'admin-ajax.php' )
add_action('wp_ajax_diplay_user_table', 'diplay_user_table');
function diplay_user_table() {
echo "function is loading in div";

I am trying to create this using AJAX to change what appears in table:


But anything that I run through function and output in div does not see the javascript needed to filter

  • When do you bind the event handlers to your markup? You have to use delegated events if the markup isn't present when the event handlers are bound.
    – Milo
    Jul 26 '17 at 15:40
  • Hi Milo, thanks for reply.I am outputting just the table rows through ajax,but I have also tried the whole table and it does the same thing..
    – aido14
    Jul 27 '17 at 0:20
  • Could you please show me an example of how delegation would work. Also I am actually opening a bootstrap tab on click too, would this matter. Here is the link: <a href='#modules-single' aria-controls='profile' role='tab' data-toggle='tab' class='mylink' data-id='".get_the_title( $lesson_id)."'>
    – aido14
    Jul 27 '17 at 0:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.