AJAX Post到PHP返回500个内部错误

AJAX Post到PHP返回500个内部错误,php,jquery,ajax,post,Php,Jquery,Ajax,Post,当AJAX请求返回500个内部服务器错误时,我遇到了一个问题,代码在运行MAMP的本地机器上运行良好,但一旦我将其移动到另一台服务器,它就会给出500个错误 我看到一些人也有类似的问题,但大多数情况下都会导致他们的代码中出现拼写错误,这段代码在MAMP上的工作与预期完全一致 如有任何建议,将不胜感激 谢谢 // Login AJAX $('#login_form').on('submit', function(e) { e.preventDefault(); var data = $(th

当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);
}

?>
//登录AJAX
$('login#u form')。关于('submit',函数(e){
e、 预防默认值();
var data=$(this.serialize();
$.ajax({
url:'core/process_login.php',
键入:“post”,
数据:{'formdata':数据},
数据类型:'json',
成功:功能(数据){
如果(data.login_status==“失败”){
警报(数据错误消息);
}
如果(data.login_status==“success”){
window.location.replace(“/index.php”);
}
}
});
});

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

我在尝试配置自定义上载脚本时遇到此问题。解决方案是把它移到我自己的服务器上,它工作得很好。你最好联系网络主机,让他们调查,因为他们可以使用错误日志。

我已经找到了错误的根源,init.php拉入了一个包含一些短标记的db_连接和ldap_连接文件,启用短标记/添加长标记解决了问题


谢谢大家的帮助。

然后检查日志。你确定没有在本地服务器上激活php或apache模块,而没有在另一台服务器上激活它吗?谢谢Leon,我已经在两台内部服务器和一台外部托管服务器上试过了,检查了所有日志,没有找到任何其他错误或详细信息。