ajax调用发生内部服务器错误

时间:2015-09-29 16:18:11

标签: javascript php jquery ajax internal-server-error

我在做ajax call。每次失败并发生500 Internal server error。但是客户端代码没有错误

JavaScript代码:

$.ajax({
    url:"test.php",
    type:"POST",
    dataType:"html",
    data:{
        userInput:userInput /* userInput is some text value */
    }
});

PHP代码:

<?php
    $con=mysqli_connect("localhost","root","password","test");
    $user_data=$_POST['userInput'];
    echo $user_data;
?>

每次我在控制台中看到这些错误代码:

POST XHR http://localhost/test.php[HTTP/1.0 500 Internal Server Error 1ms]

询问我是否需要更多信息

NB:我在这个社区发现了很多问题。 这些都没有解决我的问题

2 个答案:

答案 0 :(得分:2)

我认为内部服务器错误是由mysqli_connect函数调用导致mysqli扩展未启用。尝试phpifo()验证启用了mysqli扩展程序

答案 1 :(得分:0)

您可以捕获执行回调的错误。例如:

$.ajax({
    url:"test.php",
    type:"POST",
    dataType:"html",
    data:{
        userInput:userInput /* userInput is some text value */
    }
}).success(function() {
    window.alert('Ajax completed successfully');
}).error(function() {
    window.alert('An error has occurred');
});