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

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

如何為ajax請求中的每個表單提供另一個“警報”?

如何為ajax請求中的每個表單提供另一個“警報”?

慕絲7291255 2023-11-02 21:17:19
  let getLoginPassSystem = function (getPassForgotSystem, getLoginCheckSystem) {  $(document).ready(function () {    $('#login,#lostpasswordform,#register').submit(function (e) {      e.preventDefault();      $.ajax({        type: "POST",        url: 'http://www.virtuelles-museum.com.udev/spielelogin/logsystem.php',        data: $(this).serialize(),        success: function (response) {          var data = JSON.parse(response);          if (data.success == "accepted") {            document.getElementById('inner').innerHTML = 'Herzlich Willkommen';            // location.href = 'index.php';          } else {            alert('Ungültige Email oder Password!');          }        }      });    });  })}好吧,我想為每個表單(#login,#lostpasswordform,#register)都有一個不同的“警報”。實際上可能嗎?
查看完整描述

2 回答

?
RISEBY

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

您可以在每個 div 標簽中將警報消息保存為數據屬性。例如:


<div id="login" data-msg="message1"></div>

<div id="lostpasswordform" data-msg="message2"></div>

<div id="register" data-msg="message3"></div>



// then you can invoke them like this

let getLoginPassSystem = function (getPassForgotSystem, getLoginCheckSystem) {

  $(document).ready(function () {

    $('#login,#lostpasswordform,#register').submit(function (e) {

      e.preventDefault();

      let current_form = $(this);

      $.ajax({

        type: "POST",

        url: 'http://www.virtuelles-museum.com.udev/spielelogin/logsystem.php',

        data: $(this).serialize(),

        success: function (response) {

          var data = JSON.parse(response);


          if (data.success == "accepted") {

            document.getElementById('inner').innerHTML = 'Herzlich Willkommen';


            // location.href = 'index.php';

          } else {

            alert(current_form.attr('data-msg')); 

          }

        }

      });

    });

  })

}


查看完整回答
反對 回復 2023-11-02
?
米琪卡哇伊

TA貢獻1998條經驗 獲得超6個贊

看來你可以簡單地檢查一下e.target- 每個表格都會有所不同。

查看完整回答
反對 回復 2023-11-02
  • 2 回答
  • 0 關注
  • 173 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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