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 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了