Replies: 1 comment
-
Hi @steffejr, if you're able to read from the database and write the data to the console, then you should be most of the way there! Can you share a bit of (simplified) code so that we can see where/how you're reading the data in, and give you some tips for how to turn that data into a variable that jsPsych can use? Without having seen exactly what you're doing, one approach that comes to mind would be to initialize a global variable to hold the data, and then use the Another tip is to use dynamic parameters and event-related callback functions to access and manipulate the global variable that contains your database data, since it will be undefined when the page first loads. Here's a sketch of the general approach: var mysql_data;
var get_data = {
type: 'call-function',
async: true,
func: function(done) {
// get data from database here and store in mysql_data variable
mysql_data = result;
done(); // call the callback function to end the call-function trial once the data transfer has finished
}
}
var trial = {
// other parameters ...
stimulus: function() {
return mysql_data.stimulus[0];
}
} Would something like this work? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello all,
I would like to have a jsPsych task read from a MySQL database and I cannot figure out how to do it. Within my jsPsych code I would like to return data from MySQL that I can use within jsPsych. I have been able to read from the database and write the data via console.log() but not to get data as a variable.
Can anyone help please? Thank you.
Beta Was this translation helpful? Give feedback.
All reactions