dpd3447 2014-11-04 17:01
浏览 160
已采纳

AJAX Post to PHP返回500内部错误

I'm having an issue at the moment where AJAX requests are returning 500 Internal Server Errors, the code works fine on my local machine running MAMP, but as soon as I move it to another server it gives the 500 error.

I have seen that some people have had similar issues, but the majority of those cases have all resulted in typos in their code, this code works exactly as expected on MAMP.

Any advice would be greatly appreciated

Thanks

// Login AJAX

$('#login_form').on('submit', function(e) {

e.preventDefault();

var data = $(this).serialize();

$.ajax({
    url: 'core/process_login.php',
    type: 'post',
    data: {'formdata' : data},
    dataType:'json',
    success: function(data) {
        if(data.login_status === "failed") {
            alert(data.error_msg);
        }

        if(data.login_status === "success") {
            window.location.replace("/index.php");
        }
    }
});
});

<?php 

require('init.php');

$formdata = $_POST['formdata'];

parse_str($formdata);

if ($ldap->authenticate($username, $password)) {

    if ($ldap->user()->inGroup($username, "_BMSUsers")) {

        if(userProfileExists($username)) {

            createUserSession($username);

            $return = array("login_status" => "success");

            echo json_encode($return);

        } else {
            createUserProfile($username);

            createUserSession($username);

            $return = array("login_status" => "success");
            echo json_encode($return);
        }

    } else {

        // User is not part of the _BMSUSers AD group and therefore does not have sufficient permissions
        $return = array("login_status" => "failed", "error_msg" => "You do not have permission to access the BMS System. If you think this is a mistake, please contact the IT Department.");
        echo json_encode($return);
    }

} else {
    $return = array("login_status" => "failed", "error_msg" => "Username/Password Incorrect");
    echo json_encode($return);
}

?>
  • 写回答

3条回答 默认 最新

  • dousigan0499 2014-11-05 10:36
    关注

    I've found the root of the error, the init.php pulls in a db_connection and ldap_connection files which contained some short tags, enabling short tags/adding long tags resolved the issue.

    Thanks everyone for your assistance.

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

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog