部分代码如下:
jsPsych.init({
timeline:timeline,
on_finish: function(){
jsPsych.data.displayData();
saveData(jsPsych.data.get().csv());
}
})
function saveData(name, data){
var xhr = new XMLHttpRequest();
xhr.open('POST', 'write_data.php'); // 'write_data.php' is the path to the php file described above.
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify({filedata: data}));
}
文件write_data.php如下:
<?php
$post_data = json_decode(file_get_contents('php://input'), true);
$data = $post_data['filedata'];
$file = uniqid("session-");
$name = "data/{$file}.csv
file_put_contents($name, $data);
?>
相似问题