skip to Main Content
  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!');
          }
        }
      });
    });
  })
}

Well, I want to have for every form(#login,#lostpasswordform,#register) an different "alert". Is it actually possible?

2

Answers


  1. It seems like you can simply check the e.target – it will be different for every form.

    You can get more information about Event.target here: https://developer.mozilla.org/en-US/docs/Web/API/Event/target

    Login or Signup to reply.
  2. You can save an alert massage in each div tag as data attribute. For example:

    <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')); 
              }
            }
          });
        });
      })
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search