Hello,
I have a small problem with my script. The ajax calls php file but it wont finsih successfully. Instead it goes to error: callback.
My javascript part:
function updateUserlist(){
$.ajax({
type: "POST",
url: "process.php",
data: {"function": "userList", "n_users": n_users},
dataType: "json",
success: function(data){
console.log("Updating...");
$("#users-list ul").append("<li>"+data.text['nickname']+"</li>");
n_users = data.numUsers;
},
error: function(){
console.log("Error with updating");
}
});
}
And my PHP side:
$function = $_REQUEST['function'];
$log = array();
switch($function){
case('userList'):
/*$room_id = $_SESSION['room'];
$n_users = $_REQUEST['n-users'];
$connect->query("SELECT nickname FROM user_in_room, user WHERE user.id = user_in_room.user_id AND room_id = '$room_id'");
$results = $connect->get();
if($n_users == count($results)){
$log['text'] = false;
}else{
$text = array();
$log['numUsers'] = count($results);
foreach($results as $num => $result){
if($num > count($results)){
$text = $result;
}
}*/
//$log['text'] = $text;
$log['t'] = "asd";
}
break;
}
echo json_encode($log);
I commented the function pretty much out, thinking that It should be successfull then, but it doesnt return to success. Whats it wrong with the code ?