I basically have an ajax function which gets the latest posts from a database, what I want to know is if no data is found what should I return seeing as returning null seems to be an issue for firebug?
php code
function getLatestChat(){
global $session, $form;
$data = $session->getLatestChat(mysql_real_escape_string($_REQUEST['withUser']),
mysql_real_escape_string($_REQUEST['ignoreMessages']));
if($data){//successful
echo json_encode($data);
}
return;
}
jquery code
function getLatestChat(){
var ignoreMessagesArr = $(".chatID").map(function(){ return this.value;}).get().join(",");
$.ajax({
traditional: true,
dataType: "json",
type: "GET", url: "include/process.php",
data:{
getLatestChat: "true",
withUser: currentCCID,
ignoreMessages: ignoreMessagesArr
},
success: function(data){
$.each(data, function(i, elem){
$('.chat-latestContainer').append(elem.value);
});
}
}
});
at the moment the method either returns the $data object or null.
You can return an empty object to represent no data in the object:
Or if your Javascript code expects an array, return an empty array: