LMSouq
moodle-core Open

Using AMD and Moodle

CH
Christos312
1 month ago
3 views
Problem Description
I am trying to use jQuery in a module I am building for Moodle but I am facing a lot of problems. Based on the quide here [Moodle Docs][1] I created the folder structure required ./ ./amd ./amd/src ./amd/src/scripts.js And in my scripts.js I have simple code define(['jquery'], function($) { return { debug: function($){ console.log($); } }; }); I run grunt, everything compiles as expected. Then in my PHP I call $PAGE->requires->js_call_amd("mod_mymod/scripts", "debug", null); When I run this I get the following error > Uncaught Error: No define call for mod_mymod/scripts Can anybody help me to resolve this? I never used AMD before, so if for example I need to make something like $("#link").click(function(){ $(".results").html("hi"); } how I will do it? [1]: https://docs.moodle.org/dev/Javascript_Modules#Embedding_AMD_code_in_a_page

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base