I'm issuing a strange comportment using an ajax request with jquery, in the code below the header.STATUS can't be retrieved in a variable called 'status' it seems to work fine with another variable name, I'd like to know why ?
$.ajax({
type: "GET",
url: myConnect.prototype.URL,
data: params,
error: this.errorHandler,
success: function(data){
response = JSON.parse(data);
status = response.STATUS;
if(status.SUCCESS){ //never true since status is not an object.
console.log('success !');
}
}
});
data is : {"STATUS":{"SUCCESS":1,"DESCRIPTION":""}}
the status variable is set as a string, I can see its value in the chrome's Watch Expression view :
status: "[object Object]"
but if I call this variable 't' (or anything else) the condition will be true and it will log 'success !'
any explanation ?
EDIT : the response parsed object as displayed by chrome :
response : Object
STATUS: Object
DESCRIPTION: ""
SUCCESS: true
_proto_: Object
_proto_: Object

datadoes not exist... you called itdarain your function paramdataTypeto"json"and removeJSON.parse, let jQuery do the parsing for you. Though, in theory that shouldn't make any noticiable difference to the result. What do you get if you console.log data after it is parsed as an object?