partho
partho

Reputation: 1084

ajax call occuring internal server error

I am doing ajax call. And every time it is failing with occurring a 500 Internal server error. But no error in the client side code.

JavaScript code:

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

PHP code:

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

every time I see these error codes in console:

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

Ask me if you need more informations.

NB:I found many questions in this community. None of those solved my problem.

Upvotes: 0

Views: 572

Answers (2)

Shanavas M
Shanavas M

Reputation: 1629

I think the internal server error is due to the mysqli_connect function call with mysqli extension not enabled. Try phpifo() to verify mysqli extension is enabled

Upvotes: 2

Jonas Sciangula Street
Jonas Sciangula Street

Reputation: 1892

You can catch your error executing a callback .. example:

$.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');
});

Upvotes: 0

Related Questions