我需要解析一个数组并将其发送到一个 PHP 文件,该文件会将内容写入文件。
这是功能
var label = a.text;
GetEl('emotion-label').innerHTML = "I'm " + a.text;
$.ajax({
url: 'mehrabian_pad_subset with AB doubles 2d&3D.csv',
success: function (data) {
//parse your data
//you can split into lines using data.split('\n')
//use regex functions to effectivley parse
var new_label = GetEl('emotion-label').innerHTML;
var label_custom = data.splitCSV();
for (var i = 0; i < label_custom.length - 1; i++)
if (label_custom[i][1] == a.text)
$.post("JS/foo.php", {
data: label_custom[i]
}, function (result) {
alert("test")
}, "json");
}
});
这是我的 php 文件
<?php
$dir = '/var/www/devData/test';
// create new directory with 777 permissions if it does not exist yet
// owner will be the user/group the PHP script is run under
if ( !file_exists($dir) ) {
mkdir ($dir, 0777);
}
if (isset($_POST['data'])) {
$stringData = $_POST['data'];
$file = "/var/www/devData/test/ciao.txt";
echo $stringData;
echo "ciao";
$fh = fopen($file, 'w') or die("can't open file");
fwrite($fh, $stringData);
fclose($fh);
}
?>
有谁知道我该怎么做?