Z
Z
zeaovede2022-02-16 00:44:38
AJAX
zeaovede, 2022-02-16 00:44:38

Why can myajax fall off when reconnecting jquery?

Before that, everything worked and jquery was connected via functions

function my_scripts() { 
?>	
<script type="f71ad2114b19723ebddd10ca-text/javascript" src="<?php echo get_template_directory_uri(); ?>/js/jquery-3.6.0.min.js"></script>
<?php
}


jquery was reconnected in the same place

function my_scripts() {  
wp_deregister_script( 'jquery' );
  wp_register_script( 'jquery', get_template_directory_uri() .'/js/jquery-3.6.0.min.js' );
  wp_enqueue_script( 'jquery' );
}

620c1ec4156b6081797464.png
And now, if you look at the page code, then myajax is not connected. What could have done this?
This is how myajax is connected
add_action( 'wp_enqueue_scripts', 'myajax_data', 2000);
function myajax_data(){
  wp_localize_script( 'jquery', 'myajax',
    array(
      'url' => admin_url('admin-ajax.php')
    )
  );
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Zolin, 2022-02-16
@zeaovede

From the function descriptionwp_localize_script();
620c41ea23b77784011981.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question