1

I want to use jquery in CakePhp 3.2.7. This is an error that I am receiving.

Error:

ReferenceError: $ is not defined

I added to default.ctp :

<?php echo $this->Html->script('http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js') ?> 

How can I solve this problem?

1
  • First set remote files whitout http or https, like ``` -> script('//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js')```, after add other jquery plugins, and last is your custom js code. Commented May 15, 2016 at 8:52

2 Answers 2

2

I solved this problem:

I changed place two following lines :

1.<?= $this->Html->script('index.js') ?>

2.<?= $this->Html->script('jquery.min') ?>

to:

1.<?= $this->Html->script('jquery.min') ?>

2.<?= $this->Html->script('index.js') ?>

Sign up to request clarification or add additional context in comments.

Comments

-1
<?= $this -> Html -> script('yourFile.js') ?> /yourFile.js must be in your webroot/js folder 

If you don´t want to have a jquery.js file in your project, don´t use the helper and just put the url route to script in your default layout

<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> 

7 Comments

You can use html helper to set local and remote assets whitout any problem
@Salines how you can use html Helper to set remote js file?? give me an example pleasse! I´m open to learn all days
@Salines it´s true! its works with remote assets, i checked it at this moment, I apologize for the confused response :(
@Digipng what not working? remote jquery file not load or you have js error?
@Digipng are you tried to download the jquery file and put it in webroot/js folder?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.