Gouravdev Posted June 3, 2021 Share Posted June 3, 2021 I'm getting `Uncaught ReferenceError: $ is not defined` error. I've define my js and css under, hookBackOfficeHeader() using $this->context->controller->addJS($this->_path . 'views/js/filename.js'); can anyone help me Link to comment Share on other sites More sharing options...
Gouravdev Posted June 3, 2021 Author Share Posted June 3, 2021 14 minutes ago, Crezzur said: Did you register your hook upon installation of your module? $this->registerHook('BackOfficeHeader') Yes, I did it's only not working for Ps 1.7.6.5 Link to comment Share on other sites More sharing options...
Gouravdev Posted June 4, 2021 Author Share Posted June 4, 2021 12 minutes ago, Crezzur said: Did you add it already on install or after you have installed the module? If so reset your module to install the hook. after installed the module. Link to comment Share on other sites More sharing options...
Gouravdev Posted June 4, 2021 Author Share Posted June 4, 2021 6 minutes ago, Crezzur said: Reset your module then other while your module hook is not registered I fixed it with $this->context->controller->addJquery(); before calling module js Link to comment Share on other sites More sharing options...
Gouravdev Posted June 7, 2021 Author Share Posted June 7, 2021 On 6/4/2021 at 4:51 PM, Crezzur said: Reset your module then other while your module hook is not registered Hi the error is coming on module manager now public function hookBackOfficeHeader() { $this->context->controller->addJquery(); $this->context->controller->addCSS($this->_path . 'views/css/file.css'); $this->context->controller->addJS($this->_path . 'views/js/file.js'); Media::addJsDef([ 'base_url' => $this->context->link->getAdminLink('fileTab'), ]); } Link to comment Share on other sites More sharing options...
Gouravdev Posted June 7, 2021 Author Share Posted June 7, 2021 2 minutes ago, Crezzur said: @Gouravdev Post your addJquery function, there is an error in that function. $(document).ready(function () { /*------ Tabs functionality --------*/ $('#tabOrder a').click(function (e) { e.preventDefault() $(this).tab('show') }) Link to comment Share on other sites More sharing options...
Gouravdev Posted June 7, 2021 Author Share Posted June 7, 2021 2 minutes ago, Crezzur said: /*------ Tabs functionality --------*/ $(document).on('click', '#tabOrder a', function(clicked) { clicked.preventDefault() clicked.tab('show') }); Not sure if the error is here, try to use the code above which works better on dynamically created content. Didn't worked the error remains. The issue is in `$(document).ready(function () {` Link to comment Share on other sites More sharing options...
Gouravdev Posted June 7, 2021 Author Share Posted June 7, 2021 Uncaught ReferenceError: $ is not defined the error still remains Link to comment Share on other sites More sharing options...
Gouravdev Posted June 7, 2021 Author Share Posted June 7, 2021 I've removed everything from my JS file now it have only this $(document).ready(function () { }); The error is coming on the module manager page. In console This error is only coming for PS 1.7.6.5 to 1.7.6.9 version. Link to comment Share on other sites More sharing options...
Gouravdev Posted June 7, 2021 Author Share Posted June 7, 2021 (edited) 1 minute ago, Crezzur said: Check your page to see if your javascript file is called after jquery and not before. How I can check this? and How I can make it possible? Edited June 7, 2021 by Gouravdev (see edit history) Link to comment Share on other sites More sharing options...
Gouravdev Posted June 7, 2021 Author Share Posted June 7, 2021 Here Link to comment Share on other sites More sharing options...
Gouravdev Posted June 7, 2021 Author Share Posted June 7, 2021 Yes, How I can fix it? Link to comment Share on other sites More sharing options...
Gouravdev Posted June 7, 2021 Author Share Posted June 7, 2021 28 minutes ago, Crezzur said: Try to install this hook displayBackOfficeHeader and see if it resolves your issue. Didn't worked Link to comment Share on other sites More sharing options...
lingmaaki Posted February 28, 2022 Share Posted February 28, 2022 On 6/7/2021 at 2:12 PM, Gouravdev said: Uncaught ReferenceError: $ is not defined the error still remains If you are using any script file and getting "Uncaught ReferenceError: x is not defined " which means ‘x’ is either a variable or a method which you are trying to use before declaring it using var keyword. This means that there is a non-existent variable referenced somewhere. This variable needs to be declared, or you need to make sure it is available in your current script or scope otherwise , it will endup throwing this ‘x’ is not defined error . This usually indicates that your library is not loaded and JavaScript does not recognize the ‘x’. To solve this error: Load your library at the beginning of all your scripts. There can be multiple other reasons for this issue: Conflict with Other Libraries Path to your library included is not correct Llibrary file is corrupted Working offline (when you use CDN) Link to comment Share on other sites More sharing options...
jmauclair Posted February 28, 2022 Share Posted February 28, 2022 Instead of $(document).ready(function () { You can use window.onload = function () { It's pure JS and will not cause conflict on jquery, after the windows onload you can use $ as jquery because your page will be fully loaded Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now