lundi 28 novembre 2016

JS-Cookie: Cookies is not defined

I'm making a small website with PHP, HTML and Javascript, along with some JQuery. I'm trying to use the js-cookie library to manage javascript cookies on my site. I'm using XAMPP to run the project.

As instructed, I've downloaded the library on a directory names 'js' along with JQuery and the file for my project called app.js. Folder with Javascript

On the <head> of my index.php, I've linked the javascript code like so:

   <script src="js/jquery-3.1.1.js" charset="utf-8"></script>
   <script src="js/js.cookie.js"></script>
   <script src="js/app.js" charset="utf-8"></script>

To test that the library, I've created a simple code right at the top of my app.js (on the first two lines).

Cookies.set( 'myCookie', '1' );
console.log( Cookies.get( 'myCookie' ) );

However, when I try to run the website, I get the following errors (on Chrome):

js.cookie.js:5 Uncaught SyntaxError: Unexpected token <
app.js:1

Uncaught ReferenceError: Cookies is not defined(…)(anonymous function) @ app.js:1
app.js:1 

Uncaught ReferenceError: Cookies is not defined(…)(anonymous function) @ app.js:1
app.js:1 

I can't tell if there's a mistake in the way I'm referencing the library on index.php, or in the way I'm creating the cookie, or in the way I'm calling it.

I should also mention that I don't get the first error if I delete the link to js-cookies on my index.php.




Aucun commentaire:

Enregistrer un commentaire