2012-06-24 78 views
0

你好它真的很奇怪,即使在值为“否”后,if和else语句不能在我的函数中工作,那么也执行else部分而不是如果我的代码是如果和其他语句不工作在jquery

(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检查返回值。它的“不”,但仍然是其他部分正在工作这是如何可能?

+2

我的猜测是你没有正确测试'html'。你之后的值可能是封装。尝试使用'console.log'而不是'alert',或者在开发人员工具中检查'XHR' feed来获得正确的var来测试。 – ahren

回答

1

尝试在做检查之前修剪html。

if ($.trim(html) == 'no') 
+0

在印度的这里早上5点,你救了我不再被唤醒。谢谢 。其工作真棒使用修剪:) –

+1

酷,现在睡觉 –