I was googling for a few hours but I'm still stucked with this. I'm trying to send data to a php file with .load jquery function. I'm trying this:
$(document).ready(function() {
var commentCount = 2;
$("button").click(function() {
commentCount = commentCount + 2;
console.log("Coment Count: " + commentCount);
$("#comments").load("load-comments.php", {
'commentNewCount': commentCount
});
});
});
And my php should receive this variable as POST so I can get the information from a MySQL call.
$commentsNewCount = $_POST['commentNewCount'];
$more_comments->bindParam(':limits', $commentsNewCount, PDO::PARAM_INT);
$more_comments->execute();
$more_all_comments = $more_comments->fetchAll();
foreach ($more_all_comments as $key => $rs) {
echo '<p>';
echo $rs['author'];
echo '<br>';
echo $rs['message'];
echo '</p>';
}
I checked the console from the developer tool and I get the following error:
POST http://my_url/load-comments.php 500 (Internal Server Error)
I already try to implement a try catch in the .load function but I wasn't be able to get the error message, I printed several console.log as a mode for debugging but I don't know what could be the error.
This is for printing in real time, searched in google but can't find something like this, a lot of people use more complex functions like $.ajax or something like so I'm guessing my error is very simple.
Please, help me with your wisdom.