最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论