gpt4 book ai didi

php - php 执行时 jQuery "please wait"

转载 作者:行者123 更新时间:2023-12-01 02:04:11 26 4
gpt4 key购买 nike

我有一个连接到 PayPal API 的脚本来检查信用卡输入是否有效。该脚本可能需要大约 5 秒的时间来执行,为了防止用户在没有看到立即响应的情况下多次单击“提交”,我想放置一个“请稍候”指示器。

我有一个隐藏的 div,“pleaseWait”。在 jQuery 中我有:

$('#submit').click(function(){
$('#pleaseWait').show();
});

唯一的问题是,如果出现问题,它将发回 php 错误,并且屏幕上将继续显示“请稍候”。我决定尝试另一种方法,在脚本开始运行后在 php 中回显 jQuery,如果出现错误则将其隐藏。

 /* Echo the jQuery so the "Please wait" indicator will show on screen */
echo "<script type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js\"></script>";
echo "<script type='text/javascript' charset='utf-8'>";
echo "\$(document).ready(function(){";
echo "\$('#pleaseWait').show();";
echo "});";
echo "</script>";


if($error == ""){

/* There is not an error, run php. */

}else{
/* There was an error, stop the jQuery from displaying the "please wait" and display the error */
echo "<script type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js\"></script>";
echo "<script type='text/javascript' charset='utf-8'>";
echo "\$(document).ready(function(){";
echo "\$('#pleaseWait').hide();";
echo "});";
echo "</script>";
}

这可以工作,但看起来很困惑。除了 php 中的多个 echo 之外,还有更好的方法吗?

最佳答案

尝试使用ajax

$('#submit').click(function(){
$('#pleaseWait').show();
$.post('url',card,function(data){
$('#pleaseWait').hide();
alert(data);
})
});

关于php - php 执行时 jQuery "please wait",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5785099/

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