Reputation: 1084
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
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
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