我将数据导出到 CSV,而我使用"\r\n"
它时只是在一行上输出数据,而不是在标题行下的自己的新行上输出每组数据,即:
name | address | phone | email | greg | 2 old street | 09236462942 | greg343@gmail.com | michael | 2 new street | 0927464623 | michael343@gmail.com | ...
代码如下:
JS
var file = "Database.csv";
allData=name+","+address+","+phone+","+email;
allData=allData.replace(/[\\]/g,'');
saving();
function saving(){
$.ajax({
type: 'POST',
url: 'save.php',
timeout: 5000,
data: { data: allData, filename: file },
error: function() {localStorage["allData"]=allData; wiadomosc("Internet conection error. But don't worry, your data will be stored when conection will be stable.");},
success: function() {localStorage["allData"]="";}
});
}
PHP
<?php
if(isset($_POST["filename"]) == true && isset($_POST["data"]) == true){
$fp = fopen($_POST["filename"], "a+");
if($fp !== null){
fputs($fp, $_POST["data"] . "\r\n");
fclose($fp);
}
}
?>