In this code if/else is not working. Am I making any mistake? data.success contains true/false. If I code like this if (data.success === true) then else block is working and if block is not working and vise versa.
$scope.verifyMobile = function () {
var otp = {
"otp": $scope.mobile.otp
};
$http({
method: 'POST',
url: 'verify_mobile',
data: otp,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}).success(function (data, status, headers, config) {
if (data.success) {
$scope.verified = true;
$scope.sms_sent = false;
} else {
alert(data.message);
}
}).error(function (data, status, headers, config) {
});
};
alert(typeof data.success)before the if condition, becuaseundefinedandnullcan also be checked with the same if condition, in case yourdata.successisundefinedornullthen else part will triggerangularjsprobably he is a beginner in stackoverflow and coding that is why he tagged asjavaif (data.success)will return true as long asdata.successis not undefined nor null. Useif (data.success == true)instead.data.success[0], the success object is an array basing from your screenshot.