無法解決如何發送結果csv作爲Ajax對象返回,它足夠簡單,搜索按預期工作,但結果作爲字符串收集後發回...Ajax到PHP和返回CSV
CSV
header1 , header2 , header3, header4, header5
Foo , age-20 , male , city NY , Cars
Bar , age-32 , female , city FL , Clothes
etc...
PHP
$search = $_POST['search'];
$row = 0;
$handle = fopen("items/data.csv", "r");
$complete = array();
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if ($row == 0) {
$row++;
}else {
for ($x=0; $x < 4; $x++) {
$se = $data[$x];
if ($se == $search){
$num = count($data);
$row++;
for ($c=0; $c < $num; $c++) {
$complete[] = $data[$c] ;
}
}
}
}
}
fclose($handle);
echo json_encode($complete);
AJAX
$.ajax({
url:'search.php',
type: 'POST',
data: {search: $('#search').val()},
success: function(data) {
console.log(data);
},
error: function (error ,xml){
console.log(error);
}
})
}
林具有硬時間試圖使用該信息被返回,我deally我想它作爲一個數組();
**Returned String Output**
["Bar","Age-32","Female","city FL","Clothes"]
感謝
你能後的返回的字符串的例子嗎? – skreborn