Reputation: 5758
I am trying to use the JQuery
Cookie
plugin, below is my code that is giving me trouble.
jQuery("#orderBtn").click(function(event){
jQuery(".order-alert").show();
event.preventDefault();
var productArray = {};
//Add item to array
if (jQuery.cookie('quote_products_cookie') === undefined) {
jQuery.cookie('quote_products_cookie', JSON.stringify(productArray), { expires: 1, path: '/' });
} else {
productArray = JSON.parse(jQuery.cookie('quote_products_cookie'));
}
jQuery('#order_counter').html(Object.size(productArray));
});
I am getting this error:
Uncaught TypeError: undefined is not a function
It is saying the issue is on this line:
if (jQuery.cookie('quote_products_cookie') === undefined)
I don't know why it is giving me this error as I have included the script in my header
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script src="<?= get_template_directory_uri(); ?>/js/jquery.cookie.js"></script>
Can anyone shed any light on the issue?
Upvotes: 0
Views: 3812
Reputation: 5758
Found the problem guys, Basically I was working on some Wordpress that a colleague had done in the past and included a lot of plugins throughout the code.
Anyways, long story short, there was another version of jQuery
being included in the body
and in order to solve the issue I removed this and brought the cookie
include to the footer.php
and the problem resolved.
Upvotes: 2
Reputation: 4826
Doublecheck (triple & quadruple!) that the path to jquery.cookie.js is correct and that the file parses properly. Perhaps you should fetch a fresh copy of it just in case.
The error indicates that the file is not being included or executed properly. The same error can be produced by evaluating jQuery.nonsense() === undefined
.
Upvotes: 1