0
如何將php數組回顯到jquery $ .each函數?
這裏就是我試圖在PHP那麼遠,
$index = 0;
while(!feof($file))
{
$singleLine = fgets($file);
$totalLines[$index] = $singleLine;
++$index;
}
echo $totalLines;
以下是我正在讀回jQuery中......
$.post("sendFile.php",{fileName: sendFileName}, function(data)
{
$.each(data, function(index, value)
{
alert(value);
});
});
輸出給我數組.. 。當它應該給我Test1,Test2,Test3爲每個數組元素...
嘗試$就通過JSON發送數據,並通過獲得JSON我認爲這將爲你工作 –
@ mayank-swami - $ .post只包裝$ .ajax,所以$ .post是好的。它只需要第四個參數,即格式。例如:$ .post('file.php',{field:value},function(data){..},'json');然後它會被解析爲JSON – temporalslide