Hello,
I am new to jsPsych, and have ben trying to play around to see if I can use it for my experiment. For the mean time I want just to run the experiment on my computer, and save the data to a CSV file.
I have tried to follow the tutorial in order to do that, but I get an error.
If I run my experiment in Chrome, I get this error:
jquery.min.js:4 XMLHttpRequest cannot load file:///Users/neurotheory/Documents/Latent%20State%20Experiment/jsPsych_experiment/save_data.php. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
If I run it in Firefox, I get a different error:
no element found save_data.php:8:3
no element found experiment.html:8:3
Not sure what is the problem as I think I followed the tutorials...
here is my code:
the php file (as in the tutorial):
<?php
// the $_POST[] array will contain the passed in filename and data
// the directory "data" is writable by the server (chmod 777)
$filename = "data/".$_POST['filename'];
$data = $_POST['filedata'];
// write the file to disk
file_put_contents($filename, $data);
?>
the html experiment:
<!doctype html>
<html>
<head>
<title>My experiment</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="jspsych-5.0.3/jspsych.js"></script>
<script src="jspsych-5.0.3/plugins/jspsych-text.js"></script>
<script src="jspsych-5.0.3/plugins/jspsych-single-stim.js"></script>
<link href="jspsych-5.0.3/css/jspsych.css" rel="stylesheet" type="text/css"></link>
</head>
<body>
</body>
<script>
var post_trial_gap = function() {
return Math.floor(Math.random() *1500) + 750;
}
var welcome_block = {
type: 'text',
text: 'Welcome to the expeiment. Press any key to begin!'
};
var instructions_block = {
type: 'text',
text: "<p>In this experiment, a circle will appear in the center " +
"of the screen.</p><p>If the circle is <strong>blue</strong>, " +
"press the letter F on the keyboard as fast as you can.</p>" +
"<p>If the circle is <strong>orange</strong>, do not press " +
"any key.</p>" +
"<div class='left center-content'><img src='img/blue.png'></img>" +
"<p class='small'><strong>Press the F key</strong></p></div>" +
"<div class='right center-content'><img src='img/orange.png'></img>" +
"<p class='small'><strong>Do not press a key</strong></p></div>" +
"<p>Press any key to begin.</p>"
};
var test_stimuli = [
{
stimulus: 'img/blue.png',
data: {toDo: 'go'}
},
{
stimulus: 'img/orange.png',
data: {toDo: 'no-go'}
}
];
var test_block = {
type: 'single-stim',
choices: ['F'],
timing_response: 1500,
time_post_trial: post_trial_gap,
on_finish: function(data) {
var correct = false;
if (data.toDo ==='go' && data.rt > -1) {
correct = true;
} else if(data.toDo == 'no-go' && data.rt == -1) {
correct = true;
}
jsPsych.data.addDataToLastTrial({correct: correct});
},
timeline: test_stimuli
}
svar timeline = [];
timeline.push(welcome_block)
timeline.push(instructions_block)
timeline.push(test_block)
function saveData(filename, filedata){
$.ajax({
type:'post',
cache: false,
url: 'save_data.php', // this is the path to the above PHP script
data: {filename: filename, filedata: filedata}
});
}
jsPsych.init({
timeline:timeline,
on_finish: function(data) {
saveData("filename.csv", jsPsych.data.dataAsCSV()) }
});
</script>
</html>
--
You received this message because you are subscribed to the Google Groups "jsPsych" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jspsych+u...@googlegroups.com.
To post to this group, send email to jsp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jspsych/6e4bbf69-b5af-4f55-88ac-4660a9858b42%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/jspsych/c6ad7b2d-2c0f-4086-9d0a-9a9e7745702f%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jspsych/3b189734-5e49-45b8-831c-fb70ffb5d630%40googlegroups.com.