JQuery发布回调不起作用 [英] JQuery post callback not working

查看:89
本文介绍了JQuery发布回调不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到关于这个主题有多个问题,但我还没有找到答案。

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(简化它,因为它不工作):

PHP (simplified it since it was not working):

<?php
echo "Test";
?>

结果:没有。萤火虫中出现POST ... / signin.php错误,在不到一秒的时间内就会消失,这样我就没有机会阅读它。

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.

我已经尝试过console.log(任何东西)。

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

推荐答案

你的表单好像已经提交了,所以要防止默认表单提交,执行:

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);
   });
});

这篇关于JQuery发布回调不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆