简体   繁体   English

使用Java确认对话框破坏PHP代码?

[英]Breaking a PHP code with Javascript confirm dialog?

I have PHP scrip that goes like this: 我有这样的PHP脚本:

if ($cost_frm < $cost){
     echo "<script type='text/javascript'>
     var r = confirm('Input cost is lower than original. Sure?'));
     If (r==true){
            } else{
                            *** BREAK PHP SCRIPT ***
                           }
             </script>";
 }

And I'd like to stop ejecuting the script (or doing anything else) if the user clicks Cancel. 如果用户单击“取消”,我想停止构建脚本(或执行其他任何操作)。 Any tip? 有小费吗?

You can't! 你不能! PHP is server side, javascript is client side PHP是服务器端,javascript是客户端

为什么不将整个验证都放入javascript中呢?

好吧,我想如果不是将整个脚本分解为可以使用Ajax激活的段,而不是运行整个脚本,则可以满足您的需要。

You can't do that because the PHP is going to finish processing before the JavaScript runs. 您不能这样做,因为PHP将在JavaScript运行之前完成处理。

PHP runs completely on the server, and only when it is done does it send the output to the browser, which then processes it. PHP完全在服务器上运行,只有完成后,PHP才会将输出发送到浏览器,然后由浏览器进行处理。 So by the time that box pops up, everything will be done. 因此,当该框弹出时,一切都会完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM