duanhe6464 2011-11-21 01:40
浏览 48
已采纳

如何进行ajax登录请求

I have this in my PHP code, and it currently does the login request in the same login.php page but now i want to do it with Ajax. Basically I have this in the login.php

       echo '<form method="post" ><div id="login" class="login">
        <label for="login">User Name</label>
        <input type="text" name="logInUsername" />
        <label for="Password">Password</label>
        <input type="password" name="logInPassword" />
        <input type="submit" value="Submit"  name="submitlogin" class="button" />
        </div>';

I would like to still use this but have a login_request.php or something where i can send the username and password validated and then change the <div id=login> to say you are logged in!</div> I can do it the conventional way, with the form post .. but now I would like to try it with Ajax.

Any help will be much appreciated.

Regards

  • 写回答

4条回答 默认 最新

  • dongqijuan3786 2011-11-21 01:54
    关注

    What have you tried so far? This is how I would start:

    This should get you started:

    HTML:

    <form id="loginForm">
        <div id="login" class="login">
            <label for="login">User Name</label>
            <input type="text" name="logInUsername" />
            <label for="Password">Password</label>
            <input type="password" name="logInPassword" />
            <input type="button" value="Submit" id="submitlogin" class="button" />
        </div>
    </form>
    

    jQuery:

    $("#submitlogin").click(function() {
      inputs =   //grab then inputs of your form #loginform
        $.ajax ({
           url: "urltoyourloginphp.php",
           data: inputs,
           success: function() {
            $("#login").html("You are now logged in!");
        }
      });
    })
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM