LMSouq
moodle-core Open

JavaScript missing parametar

MO
Moirae
1 month ago
3 views
Problem Description
I am coding a block type plugin for Moodle and have this JS code that gives me problems. Since I'm not very familiar with JS and JSON I can't deduce what is the problem. My code uses this function to add custom action to action link which issues ajax call to php file ... This is the code: function block_helpdesk_sendemail(e) { e.preventDefault(); Y.log('Enetered method'); var sess = {'sesskey=':M.cfg.sesskey}; Y.log(sess); var ioconfig = { method: 'GET', data: {'sesskey=':M.cfg.sesskey}, on: { success: function (o, response) { //OK var data; try { data = Y.JSON.parse(response.responseText); Y.log("RAW JSON DATA: " + data); } catch (e) { alert("JSON Parse failed!"); Y.log("JSON Parse failed!"); return; } if (data.result) { alert('Result is OK!'); Y.log('Success'); } }, failure: function (o, response) { alert('Not OK!'); Y.log('Failure'); } } }; Y.io(M.cfg.wwwroot + '/blocks/helpdesk/sendmail.php', ioconfig); } The code pauses in debugger at return line: Y.namespace('JSON').parse = function (obj, reviver, space) { return _JSON.parse((typeof obj === 'string' ? obj : obj + ''), reviver, space); }; I've put M.cfg.sesskey and data variables on watch. I can see sesskey data shown, but data variable shows like this: data: Object debuginfo: "Error code: missingparam" error: "A required parameter (sesskey) was missing" reproductionlink: "http://localhost:8888/moodle/" stacktrace: "* line 463 of /lib/setuplib.php: moodle_exception thrown * line 545 of /lib/moodlelib.php: call to print_error() * line 70 of /lib/sessionlib.php: call to required_param() * line 7 of /blocks/helpdesk/sendmail.php: call to confirm_sesskey()" And this is what my logs show: Enetered method Object {sesskey=: "J5iSJS7G99"} RAW JSON DATA: [object Object]

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