I want to check if json data is empty or not.
if json its empty, i want to alert orders Not Found.
If its not empty, i want to alert orders found.
if user not logged in, there won't be any token in his localstorage. so he will get a 500 error when browser requests the API URL. then I want to alert failed along with the failed status reason
my dev is sick, so tried my self. its not going too well.
Tried the below code, not at all working.
<script>
$http.get("http://localhost.com/activeorders/?format=json",{
headers: {'Authorization': 'Token '+ localStorage.getItem("token")}})
.success(function(response) {
if(response=="[]")
{
alert(" orders NOT found");
}
else
{
alert("orders found");
}
.error(function(response,status) {
alert("failed");
alert(status);
}
return ;
});
</script>
Any help will be thankfull.