У меня есть два массива. 1 пуст, а у других есть 5 предметов. Я хочу их пересчитать и отобразить.Ajax return неправильный результат
я отправить запрос AJAX, как это:
function countTrash()
{
$.ajax({
type: "GET",
url: "count_trash_delete.php",
data: "action=1",
success: function(response){
$("#badge3").html(response);
}
});
}
function countRemove()
{
$.ajax({
type: "GET",
url: "count_trash_delete.php",
data: "action=2",
success: function(response){
$("#badge2").html(response);
}
});
}
Мой count_trash_delete.php выглядит следующим образом
if(isset($_GET['action'])) {
$action = 1;
}else{
$action = 2;
}
if($action === 1){
$trash_arr = file_get_contents('trash_bots.json');
$trash_arr = json_decode($trash_arr);
$number_of_trashed = count($trash_arr);
echo $number_of_trashed;
}elseif($action === 2){
$remove_arr = file_get_contents('remove_bots.json');
$remove_arr = json_decode($remove_arr);
if(!empty($remove_arr)){
$number_of_removed = count($remove_arr);
echo $number_of_removed;
}else{
echo 'Empty';
}
}
Когда я получить ответ оба 5. Что я не могу понять.
ооо .. я не могу верить я не видел. большое спасибо – MHH