gpt4 book ai didi

javascript - Ajax 字符串比较

转载 作者:行者123 更新时间:2023-11-30 00:08:49 25 4
gpt4 key购买 nike

我有一个基本的ajax函数

 setInterval(function() {
var action = '';
var status = '';
$('#php-data').load('../Data/Dashboard.Data.php');
$.ajax({type: 'POST', url: 'Data/Dashboard.Image.php', data: { json: action }, dataType: 'json' }).done(function(data) {
console.log('Ajax Data: ' + data);
status = JSON.parse(data);
**if(status === 'false') {**
console.log("script is NOT running");
drawPieChart();
} else {
console.log("script is running");
$('#php-image').load('../Data/Dashboard.Image.php'); //todo only load this is the ajax returned from Dashboard.image.php is true
}
});
}, 5000);

基本上我的 ajax 返回的唯一东西是“false”,所以当我将 status 与 false 进行比较时,它应该是 true 并且 drawPieChart();但是它总是运行 jquery load() 函数,即使我的 ajax 数据每次都返回 false。我也试过这个:

 setInterval(function() {
var action = '';
var status = '';
$('#php-data').load('../Data/Dashboard.Data.php');
$.ajax({type: 'POST', url: 'Data/Dashboard.Image.php', data: { json: action }, dataType: 'json' }).done(function(data) {
console.log('Ajax Data: ' + data);
status = data;
**if(status === 'false') {**
console.log("script is NOT running");
drawPieChart();
} else {
console.log("script is running");
$('#php-image').load('../Data/Dashboard.Image.php'); //todo only load this is the ajax returned from Dashboard.image.php is true
}
});
}, 5000);

还有这个:

 setInterval(function() {
var action = '';
$('#php-data').load('../Data/Dashboard.Data.php');
$.ajax({type: 'POST', url: 'Data/Dashboard.Image.php', data: { json: action }, dataType: 'json' }).done(function(data) {
console.log('Ajax Data: ' + data);
**if(data == 'false') {**

console.log("script is NOT running");
drawPieChart();
} else {
console.log("script is running");
$('#php-image').load('../Data/Dashboard.Image.php'); //todo only load this is the ajax returned from Dashboard.image.php is true
}
});
}, 5000);

最佳答案

if(status === 'false')

这暗示了一个字符串。改用这个:

if(status == false)

你可以像这样进一步简化它:

if(!status)

关于javascript - Ajax 字符串比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37350766/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com