0
$.ajax({
url: '/dir/file.php',
type: 'post',
dataType: 'json',

data: {action: 'ftype', btype: btype, urlForPagi: urlForPagi},

success: function(json){

if(typeof json.success !== 'undefined'){

$(document).find('.loadItemsHere').html(json.success);

} else if(typeof json.error !== 'undefined'){


return alert(json.error);

}
},
error: {...}
});


    $result[] = array();

    $items = $peger->getItems("SELECT * FROM `budget` WHERE `type` = '".$btype."' ORDER BY `id` DESC");

    foreach($items as $budget){

    $result[] = array(
    'id'   =>  $budget['id'],
    'type' =>  $budget['type']
    );

}

echo json_encode(['success' => $result], JSON_UNESCAPED_UNICODE);

В итоге возвращается пустота, почему?

var_dump() если сделаю, то увижу что приходит все правильно: id и type

1 Answers1

0

Сначала создаем массив $results = array();

Потом в

foreach($items as $item){

... $json = '<div>...</div>';

array_push($results,$item); }

echo json_encode(['success' => $results], JSON_UNESCAPED_UNICODE);