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 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序