sanjihan sanjihan - 2 months ago 21
Ajax Question

getting the server response caused by ajax POST method

I am trying to send POST data to the server. This is the ajax code that I use. On the other side I use mySQL and PHP. How can I see what the

output was? Currently my code is not working and I am not sure why. Getting the output from
is probably the best way to start.

url: "insertToDB.php",
type: 'POST',
data: {'lastname':'Cena','name':'John', 'email':''},
success: function(response) {

on the PHP side I have:

require_once 'login.php';

$conn = new mysqli($hn,$un,$pw,$db);
if ($conn->connect_error){

$url = $_POST["lastname"];
$name = $_POST["name"];
$email = $_POST["email"];

$query = "INSERT INTO testtable (url ,name ,email) VALUES ('$url', '$name', '$email')";
$result = $conn->query($query);
if (!$result){


The first argument to the success function is the output.

That is, if you console.log(response) instead of console.log("success"), you'll see whatever the server wrote back to the response stream.

(If you're talking about log output on the server side, that's an entirely different matter. Then we'll need to see your serverside code, not the AJAX call.)