Reputation: 1526
On the success function of jquery ajax request i am displaying a message in span
tag.
success: function(data) {
if(data = true) {
$("#result").text("is available");
}else {
$("#result").text("is not available");
}
});
When data is true then "is available
is display which is ok but when data is false then still it display "is available
instead of "is not available
.
Upvotes: 0
Views: 1109
Reputation: 18891
data = true
needs to be data === 'true'
.
data = true
attempts to set the value of data
to the Boolean true
. data === 'true'
compares data
to the string 'true'
.
Upvotes: 1
Reputation: 1804
You just want to test if data exists. Use the following
success: function(data) {
if(data) {
$("#result").text("is available");
}else {
$("#result").text("is not available");
}
});
Upvotes: 0