lundi 23 mai 2016

WordPress 4.5.2: Uncaught ReferenceError: JQuery is not defined

Why my code is unable to run and brower's console is producing error "JQuery is not defined" even though I am en-queuing my JavaScript file into the plugin properly.

As per source code, JQuery Library file before is also importing before my JavaScript file.

Please take a look at the code below and let me know if I am doing something wrong:

File Path: wp-content/plugins/AjaxTest/AjaxTest.php

<?php
/*
Plugin Name: Ajax Test
Description: This is a Ajax Test plugin
Version: 1.0
*/

function add_ajax_file()
{
    wp_enqueue_script('ajax-test', plugins_url('/js/ajax.js', __FILE__), array('jquery'));
}

add_action('wp_enqueue_scripts', 'add_ajax_file');

File Path: wp-content/plugins/AjaxTest/js/ajax.js

JQuery(document).ready( function($){

    alert("Hello");
});

Error Message in Console:

Uncaught ReferenceError: JQuery is not defined
(anonymous function)    @   ajax.js?ver=4.5.2:1

Order of JavaScript files in source code after running above code into the browser:

<script type='text/javascript' src='http://localhost/wordpress1/wp-includes/js/jquery/jquery.js?ver=1.12.3'></script>
<script type='text/javascript' src='http://localhost/wordpress1/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.4.0'></script>
<script type='text/javascript' src='http://localhost/wordpress1/wp-content/plugins/AjaxTest/js/ajax.js?ver=4.5.2'></script>

As suggested on web from WordPress users with similar problem, I have already tired adding below code into the wp-config.php file but no luck

define('CONCATENATE_SCRIPTS', false);

I am using WordPress 4.5.2



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire