以下是ajax請求。Ajax請求不返回任何內容。爲什麼?
$.post('delete.php', {'deletearray':deletearray, 'dir':dir}, function(deleted, undeleted){
if(undeleted == 0) {
alert('All ' + deleted + ' files delted from the server');
} else {
alert(deleted + ' files deleted and ' + undeleted + ' files could not be deleted');
}
}, 'json');
,並在這裏不用的delete.php
<?php
if(isset($_POST['deletearray'])) {
$files = $_POST['deletearray'];
$dir = $_POST['dir'];
$deleted = 0;
$undeleted = 0;
foreach($files as $file) {
if(unlink($dir.$file) && unlink($dir.'thumb/'.$file)) {
$deleted ++;
} else {
$undeleted ++;
}
}
echo json_encode($deleted, $undeleted);
}
return;
?>
截至上運行它成功地刪除文件,但沒有消息顯示的代碼。
我還試圖改變AJAX請求爲:
$.post('delete.php', {deletearray:deletearray, dir:dir}, function(deleted, undeleted){
alert("php finished");
}, 'json');
仍然不顯示該消息。所以我想在delete.php文件中有錯誤。請幫忙。
如果問題是在PHP中,你爲什麼不檢查錯誤日誌?或者JavaScript控制檯呢! –
您可能正在尋找'$ _POST ['deletearray']',而不是'$ _POST [deletearray]'。 – sevenseacat
也是'$ _POST ['dir']' – UserProg