亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 PHP 中提交表單后的警報消息

在 PHP 中提交表單后的警報消息

PHP
收到一只叮咚 2022-09-03 16:24:33
我正在使用帶有POST方法的表單來應用會話,一旦表單提交,頁面就會重新加載,并且屏幕上沒有任何警報。所以我使用了一些我在網上找到的技巧,但它有一個問題,在表單提交后彈出警報,但沒有一個頁面設計工作,這意味著我只有空白頁和警報消息。單擊“確定”關閉警報消息后,頁面將加載。if(empty($_SESSION["shopping_cart"])) {    $_SESSION["shopping_cart"] = $cartArray;    $status = "Product is added to your cart!";    header('location:product.php?status=success');}else{    $array_keys = array_keys($_SESSION["shopping_cart"]);    if(in_array($code,$array_keys)) {        $status = "Product is already added to your cart!";        header('location:product.php?status=failed');    } else {        $_SESSION["shopping_cart"] = array_merge($_SESSION["shopping_cart"],$cartArray);        $status = "Product is added to your cart!";        header('location:product.php?status=success');    }}// This right here responsible to alert the message according to the status.if( $_GET['status'] == 'success') {   echo '<script>  alert("welldone");   </script>';}else{   echo '<script>  alert("no good");   </script>';}如何解決頁面加載順序,使頁面首先加載,警報加載后?
查看完整描述

4 回答

?
翻閱古今

TA貢獻1780條經驗 獲得超5個贊

經過長時間的研究,我找到了使用jQuery函數延遲警報消息的解決方案,延遲允許HTML頁面加載然后執行警報。感謝所有幫助我取得這個結果的人。delay()


  <script>

      $(document).ready(function(){

          setTimeout(function() {

              <?php

              if( $_GET['status'] == 'success') {

                  echo 'alert("welldone");';

              }

              else{

                  echo 'alert("no good");';

              }

              ?>

              }, 500);

      });

  </script>


查看完整回答
反對 回復 2022-09-03
?
守著一只汪

TA貢獻1872條經驗 獲得超4個贊

請嘗試此代碼,在PHP中提交表單后提醒消息。


<?

if ($_POST)

    {

    if (empty($_POST['testabc'])) $msg='<script type="text/javascript">alert("BLANK");</script>';

    else $msg='<script type="text/javascript">alert("NOT BLANK");</script>';

    }

?>

<html><head></head><body>

<table>

    <tr>

        <td>

            <form id="finfo" method=POST>

                <input type="text" name="testabc">

                <input type="submit" value="info">

            </form> 

        </td>

    </tr>

</table>

<script type="text/javascript">alert("auto");</script>

<? echo $msg; ?>

</body></html>


查看完整回答
反對 回復 2022-09-03
?
慕姐4208626

TA貢獻1852條經驗 獲得超7個贊

alert()停止腳本的執行和 HTML 頁在調用該頁的點的加載。應將此腳本移動到頁面底部。



查看完整回答
反對 回復 2022-09-03
?
人到中年有點甜

TA貢獻1895條經驗 獲得超7個贊

您可以延遲腳本標記,直到呈現頁面后才會加載。

<script src="alert.js" defer></script>

然后它將在頁面呈現后加載,并且不會有隨機延遲(如使用等待/jquery延遲)。


查看完整回答
反對 回復 2022-09-03
  • 4 回答
  • 0 關注
  • 108 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號