Reputation: 33
Good day every one, i was working with ajax to check if the values are same or not, i am getting true data on ajax success but when i am using if statement for js alert its giving me opposite result, please assist- here is my code--
index.php
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js">
</script>
<script type="text/javascript">
$(function() {
setInterval("alert()", 5000);
});
function alert() {
var aval=1;
$.ajax({
type: "POST",
url: "php.php",
data: 'uid=' + aval,
success: function(html)
{ // this happen after we get result
if (html.success == true)
{
alert ('Same Value');
}
else {
alert('Different Value')
}
}
});
}
</script>
Old Value:1<br>
<div>New Value:</div><div id="new" ></div>
php.php
<?php
//some php coding which shows result
echo '1';
?>
Upvotes: 0
Views: 336
Reputation: 2964
Change your success part to this:
success: function (html) {
if (html == '1') {
alert('Same Value');
} else {
alert('Different Value');
}
}
This will check against the value (1 in this case)
Upvotes: 1