Ajax request returns nothing. why?

前端 未结 3 1965
无人共我
无人共我 2021-01-24 12:14

Below is the ajax request.

$.post(\'delete.php\', {\'deletearray\':deletearray, \'dir\':dir}, function(deleted, undeleted){
    if(undeleted == 0) {
        aler         


        
3条回答
  •  不知归路
    2021-01-24 12:43

    You should use json_encode like following:

    json_encode(array('deleted' => $deleted, 'undeleted' => $undeleted));
    

    And you have to get vars with data.undeleted and data.deleted

    $.post('delete.php', {'deletearray':deletearray, 'dir':dir}, function(data) {
        if(data.undeleted == 0) {
            alert('All ' + data.deleted + ' files delted from the server');
        } else {
            alert(data.deleted + ' files deleted and ' + data.undeleted + ' files could not be deleted');
        }
    }, 'json');
    

提交回复
热议问题