I have a data string in Javascript and I would like to store it in a text file in my server.
The normal thing to do is to send the data to a PHP medium file to process it and do the file storage part.
This is the code I used but it looks like it doesn't run at all as the destination file matrice.txt is still blank :
script.js
function finalCoords() {
for(var i = 0; i < sort_data.length; i++) {
matrix = [data.nodes[i].name, sort_data[i].x, sort_data[i].y, sort_data[i].z]; /* This data is collected from other arrays */
var matrixStr = matrix.join(" "); /* This is the string I want to store */
console.log(matrixStr);
$.ajax({
url: "matrice.php", /* This is the PHP Medium */
data : matrixStr,
cache: false,
async: true,
type: 'post',
timeout : 5000
});
}
}
matrice.php
<?php
$file="matrice.txt"; /* This is the destination file */
$text=serialize($_POST);
$fh = fopen($file, 'a') or die();
fwrite($fh, $text."\n");
fclose($fh);
?>
What is the problem and how can I fix it ?
Thanks!
postwas successful or not.