gpt4 book ai didi

jquery - 从 URL 获取变量

转载 作者:行者123 更新时间:2023-12-01 05:13:25 25 4
gpt4 key购买 nike

我正在检查是否超出了任务必须完成的时间,以发送警报。Jquery 代码:

function session_checking1()
{
$.post( "./alertaposicionamento", function( data ) {
if(data == "-1")
{
alert('Tem posicionamentos em atraso!');
}
});
}
var validateSession1 = setInterval(session_checking1, 10000);

alertaposicionamento 页面上,我有以下 php:

$result1 = mysqli_query($conn, $query2);  
while($row = mysqli_fetch_array($result1))
{
$teste = $row["codigo"];
$teste1 = $row["Colaborador"];
$teste2 = $row["FimTarefa"];
$teste3 = $row["TipoPeriodicidade"];
$teste4 = $row["Tempo"];
$teste5 = $row["Ala"];
$teste8 = $row["nome"];
}

$query = "SELECT iduser, hostname FROM raddb.sessoes
WHERE datafim IS NULL AND hostname = '$teste5'";
$result = mysqli_query($conn, $query);
while($row1 = mysqli_fetch_array($result))
{
$teste6 = $row1["iduser"];
$teste7 = $row1["hostname"];
}

if($teste4 > $teste3 AND $teste5 == $teste7 AND $teste6 == $_SESSION['usuarioId'])
{
//expired
echo "-1";
}
else
{
//not expired
echo "1";
}

它工作正常并且符合我的意图。我想要进行改进,我想要获取 $test8 变量的值,通过 URL 发送它,并将该变量的值添加到我在 Jquery< 内的消息中 alert('Tem posicionamento em atraso do (以及 $test8 变量的值)!');

最佳答案

您需要将值与您的响应一起发回

header('Content-Type: application/json');
if($teste4 > $teste3 AND $teste5 == $teste7 AND $teste6 == $_SESSION['usuarioId'])
{
//expired
echo json_encode(["status"=>"-1","value"=>$teste8]);
}
else
{
//not expired
echo json_encode(["status"=>"1","value"=>$teste8]);
}

然后将你的js更改为

if(data.status == "-1")
{
alert('Tem posicionamento em atraso do '+data.value);
}

关于jquery - 从 URL 获取变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56786910/

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