我有一个将检查文件的脚本,然后该文件返回1或0.但即使它返回1,脚本也会提醒其他人。 为什么这不起作用?
当我提醒txt时它显示0但是当txt为1时,警报(txt)给我1。
所以我的问题是,为什么不喜!当txt为1时出现?
$(document).ready(function(){
setInterval(function(){
//code goes here that will be run every 5 seconds.
var txt = '';
$.ajax({
type: "POST",
url: "checkfolder.php",
success: function(result) {
txt = result + '';
if (txt == "1"){
alert("Hi!");
}
else{
alert(txt);
}
}
});
}, 5000);
});
答案 0 :(得分:0)
试试txt.trim() 我觉得空间有问题。
答案 1 :(得分:-1)
var txt;
$(document).ready(function(){
setInterval(function(){
//code goes here that will be run every 5 seconds.
$.ajax({
type: "POST",
url: "checkfolder.php",
success: function(result) {
txt = result;
if (txt === "1")
{
alert("Hi!");
}
else{
alert(txt);
}
}
});
}, 5000);
});