dsj2014 2010-03-23 19:21
浏览 63
已采纳

使用ajax登录表单,无需刷新即可提交

I am using this tutorial to create a login form http://www.ryancoughlin.com/2008/11/04/use-jquery-to-submit-form/

It authenticates against w/ our ldap server.

What I am having a problem with is the line

success: function(){
 $('form#submit').hide(function(){$('div.success').fadeIn();});

It runs success even though we don't even know if the username and password binded successfully.

Is there a way to only run success if the username and password posted was binded successfully?

EDIT:

Added php code of ldap-login.php

<?php

ini_set('display_errors',1);
error_reporting(E_ALL);
require_once('/web/ee_web/include/adLDAP.php');
$adldap = new adLDAP();
if (isset($_POST['username']) && isset($_POST['password'])) {
    $username = $_POST['username'];
    $password = $_POST['password'];  // associated password

    // connect to ldap server
    $authUser = $adldap->authenticate($username, $password);
    if ($authUser === true) {
        $_SESSION['user_session'] = $username;
        if(isset($_SESSION['user_session'])) {
            print "ok";
        }   
    }
    else {
      print "User authentication unsuccessful";
    }
}
?>
  • 写回答

4条回答 默认 最新

  • drrkgbm6851 2010-03-23 19:27
    关注

    If your response comes back having a simple string "ok" or the error message, you can check it this way:

    success: function(data){
      if(data === "ok") {
        $('form#submit').hide(function(){$('div.success').fadeIn();
      } else {
        alert(data); // If not "ok", show error message
      }
    });
    

    Alternatively, send/check a more complex JSON response.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料