AJAX Post-to-PHP返回500内部错误


AJAX Post to PHP returns 500 Internal Error

AJAX请求返回500个内部服务器错误时,我遇到了一个问题,该代码在运行MAMP的本地机器上运行良好,但一旦我将其移动到另一台服务器,就会出现500个错误。

我看到有些人也遇到过类似的问题,但大多数情况下都会导致他们的代码出现拼写错误,这段代码在MAMP上的工作与预期完全一样。

如有任何建议,将不胜感激

感谢

// 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);
}
?>

问题可能与两台服务器上的php版本不同,我猜您使用的是一些过时的函数。500内部错误是服务器端错误,而不是客户端

我在尝试配置自定义上传脚本时遇到了这个问题。解决方案是把它移到我自己的服务器上,它运行得很好。你最好联系网络主机并要求他们进行调查,因为他们可以使用错误日志。

我已经找到了错误的根源,init.php拉入了一个db_connection和ldap_connection文件,其中包含一些短标签,启用短标签/添加长标签解决了问题。

感谢大家的帮助。