Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

Java script JQUERY in website: ReferenceError: $ is not defined

By
Ralph LAvaud
on 4/30/15, 2:15 PM 3,831 views

Hello, I am trying to write some JQUERY code in a .js file. No matter how is write the code I get a

ReferenceError: $ is not defined

I know this is related to jquery and I looked at other .js file and they seem to reference $ just fine. What I am missing? Even this errors out


(function () { 

$(document).ready(function() {

});

}());


3
Shawn Varghese
On 4/30/15, 4:01 PM

Do you need the () at the end?

Try:

(function () {
 $(document).ready(function() {
});

});

Shawn this seems to work but I think my problem goes deeper. My code requires jquery so I need to put it at the bottom after all the other JavaScript files, would you you know how to do that?

Ralph LAvaud
on 4/30/15, 6:51 PM

If I understood your question correctly, I think Nedas's answer below would address it. If you could let us know more specifically what you need, we could explain better with code snippets.

Shawn Varghese
on 5/2/15, 4:19 AM
1
Nedas Zilinskas
On 5/1/15, 7:54 AM

Hi Ralph,

This might mean that you include your file before the jQuery is loaded.

To make sure you include your file after jQuery library you would need to extend either "website.assets_frontend" or "website.assets_backend" depending where you use it.

See example inheritance of "website.assets_frontend" template below.

<template id="assets_frontend" inherit_id="website.assets_frontend">
    <xpath expr="." position="inside">
        <script type="text/javascript" src="/module_name/static/src/js/filename.js"/>
    </xpath>
</template>

The code above extends "website.assets_frontend" and includes new JS file to the bottom (position="inside") of the list meaning all other JS files will be loaded before this.

I am also facing the same error on loading my template. I have added my JS file in the 'assets_frontend' like you said, but it didn't resolve the problem.

Gopakumar N G
on 5/30/16, 8:02 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 4/30/15, 2:15 PM
Seen: 3831 times
Last updated: 6/18/15, 4:04 AM