user2859066
user2859066

Reputation: 121

JQuery post callback not working

I saw that there are multiple question on this topic, but I didn't find an answer yet.

JS:

$("#signin-form").submit(function(){
   $.post("signin.php", {email: $("#signin_email").val(), password: $("#signin_password").val()}, function(data){
        console.log(data);
   });

});

PHP (simplified it since it was not working):

<?php
echo "Test";
?>

Result: nothing. And an "POST .../signin.php" error in firebug, that dissappears after less than a second which doesn't give me the chance to read it.

I already tried console.log("anything") too.

Upvotes: 1

Views: 3789

Answers (1)

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100175

your form seems to be getting submitted, so prevent the default form submission, do:

$("#signin-form").submit(function(evt){
   evt.preventDefault();
   $.post("signin.php", {email: $("#signin_email").val(), password: $("#signin_password").val()}, function(data){
        console.log(data);
   });
});

Upvotes: 3

Related Questions