I am trying to populate am empty object with data being returned from a POST request. The data is being returned successfully, but in the code the object is found to be null. The code is given below:
var item = {};
var args= {p: "<?php echo $id; ?>"};
$.post('api.php', args, function(response) {
startSpinner(spinner);
if (response.status == 0) {
item = response.data;
console.log("ITEM: " + JSON.stringify(item));
}
}).done(function() {
..
});
if (item == null || item == undefined) {
alert("TTEMST");
}
In the console log, the item is clearly being shown to get populated with data, but the if condition for a null object is somehow being satisfied, i.e. the alert box is being displayed. I think there is something wrong with the way I am populating the object. Please help!!