Javascript error

Javascript error

by Nilesh Pathade -
Number of replies: 2

I want to use jquery in my moodle page. 

I have try $PAGE->requires->jquery();

It showing me error 

Can not add jQuery plugins after starting page output!
Please check attached file. Line no 597

Average of ratings: -
In reply to Nilesh Pathade

Re: Javascript error

by Nilesh Pathade -

Please look into this, maybe I am going something wrong with JS.


I am using external jquery.min.js file and it's working fine. but when I am going to submit plugin code checker showing me lots the errors of coding standards. So I feel that and ideally I should use  $PAGE->requires->jquery(); of Moodle jquery lib.


But it's showing me 

Can not add jQuery plugins after starting page output!
Please help me out.
In reply to Nilesh Pathade

Re: Javascript error

by Justin Hunt -
Picture of Particularly helpful Moodlers Picture of Plugin developers

You are calling :$PAGE->requires->jquery() too late.

You need to call that before you call $renderer->header() or $OUTPUT->header()

Depending on your plugin, you may not be in a situation to do that. In that case, you should try to write your javascript as AMD modules which will have jquery available to them.

https://docs.moodle.org/dev/Javascript_Modules