首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >为什么jspsych数据储存在服务器上的文件空白?

为什么jspsych数据储存在服务器上的文件空白?

提问于 2022-09-25 20:45:35
回答 0关注 0查看 52

部分代码如下:

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);

?>

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档