你好奇怪if if和else语句在我的函数中没有工作,即使在值为“no”之后也会执行else部分而不是如果我的代码是
(function pollmsg() {
setTimeout(function () {
var demon = $('.msgnotimore').val();
alert(demon);
var a = $('.gvpgvpxgvp').val();
$.ajax({
url: 'modules/notifications/beast.php?nid=' + demon + '&id=' + a,
success: function (html) {
if(html == "no") {
alert('no');
} else {
alert('ok');
$('.msgnotimore').val();
$('.notiloadmsg').prepend($(html).fadeIn('slow'));
}
},
dataType: "html",
complete: pollmsg
});
}, 30000);
})();
});
我提醒html检查返回的值。它的“不”但仍然是其他部分正在发挥作用这是怎么回事?
答案 0 :(得分:1)
在检查之前尝试修剪html。
if ($.trim(html) == 'no')