I want to test if the data array in the code below has content, because when a user gives a packageid (variable in the code below) that doesn't exist i want the else from the "if...else" to be executed. When i put in a packageid that exists everything works fine, but when i put in no number or a number that doesn't exist, the else side does't get evaluated.
function getInfoAndStatus(){
sym.$("customer_name").empty();
packageid = $("#tracknrfield").val();
var url = "http://student.howest.be/sylvain.vansteelandt/fedex/server/getPackageTracking.php?id=" + packageid;
$.getJSON(url,function(data){
if(data && data[0].id){
$("<span />", {
text: "Customer name: " + data[0].customer_name + " " + data[0].customer_firstname
}).appendTo(sym.$("customer_name"));
} else {
$("<span />", {
text: "The package with number " + packageid + " has not been found. Please try again."
}).appendTo(sym.$("customer_name"));
}
});
}
getInfoAndStatus();
datahas any values?