Howto call a js function?

Hello, i am trying to call a function of a js script to generate a vote but its not working…

i do:

<?= $this->Html->script('vote-jquery',['block'=>true]); ?>
test

but the browser says:

Uncaught TypeError: $(…).vote is not a function

thank you for helping…

Seems like there’s a problem somewhere in your vote-jquery.js. Maybe it requires that jQuery be loaded first and that’s not happening?

Any reason why you’re loading your JavaScript in the HTML header? ['block'=>true]
Just that if there’s any DOM reference and it runs before the page loads you’ll get errors.

And although you didn’t state, I’m assuming this code has come from a template.

But its what Zuluru said, that’s a jQuery call so ensure you’re loading that too - and the version your script is expecting.

no jquery was included
i just forgot to surround it with
$(function(){ });

Aha easily done. And as you’re using the jQuery ready your DOM would have loaded, so no issues with that either.

I found this on my system…but all off this js file not load at chrome ubuntu…works well at windows 10 chrome…cakephp 2

I guess you’re using the parent .. to get out of the /js/ folder to load the scripts from within the /theme folder.

Maybe its possible the browser on your Ubuntu doesn’t support the script. Or you have a web-based firewall / antivirus which didn’t like the look of those scripts.

What you can do is directly type that full address into the browser to see if it shows the actual js file in text, like: -
http://your.domain.here/theme/LamanPuteri/js/fullcalendar/fullcalender.min.js

As I typed that it also occurred to me it may not like the capitals L & P in LamanPuteri. Linux is case-sensitive which carries over to web-addresses.

1 Like

If i inspect the browser I click on url theme/LamanPuteri/js/… and it open thats file on new tab…all is working fine…that show us that the link is working fine…maybe i need to check “web-based firewall / antivirus which didn’t like the look of those scripts”…

Just make a stand-alone html which loads and calls that js.

If that works you can try doing Ctrl+U to view the source of your Cake app, and save that as HTML.
Then use that as stand-alone on your webpage, removing lines and such until it works.
That’s probably not much different to just modifying the cake app, but at least you don’t have to worry about breaking your app.

Also test on other devices & browsers. If its only the Ubuntu messing up, maybe try looking at other Cake sites with it - as it could be an issue with the browser (like some funky DNS resolver, or executing ready before the DOM has loaded, or not handling a setTimeout / setInterval properly, anything which may be too modern / unsupported in those calendar JS’s) - and out of your control.

1 Like