theme development - How to load jQuery with Ajax in WP version 5.3.2?

I am building a custom theme and using wp_enqueue_scripts to load a custom JS file for a specific page template.As you

I am building a custom theme and using wp_enqueue_scripts to load a custom JS file for a specific page template. As you can see I declared jquery as a dependency...

function enqueue_theme_scripts() {
  if (is_page_template('template-contact.php')) {
    wp_enqueue_script(
      'template-contact-js',
      get_bloginfo('template_directory') . '/template-contact.js',
      array('jquery'),
      false,
      true
    );
  }
}
add_action('wp_enqueue_scripts', 'enqueue_theme_scripts');

This is what I have in the JS file...

(function($) {
  $(document).ready(function() {
    console.log($);
    console.log($.ajax);  
  });
})(jQuery);

This is what the 'console' tab shows...

jQuery is loaded, but the $.ajax method is not included.

This is what the 'sources' tab in the Inspector shows...

As you can see it is loading jQuery version 3.4.1, but line 48 seems to indicate that ajax is being removed. How do I get jquery to load with the ajax method included?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744704611a4588979.html

相关推荐

  • theme development - How to load jQuery with Ajax in WP version 5.3.2?

    I am building a custom theme and using wp_enqueue_scripts to load a custom JS file for a specific page template.As you

    1天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信