简体   繁体   English

$ .post不适用于提交类型输入

[英]$.post is not working with the submit type input

I am working on this project and i want to update the database after being clicked on the signUp button, but the $.post() is not working and i can't find any error as no error is even being shown in the firebug of the firefox, Please help me out, I'm stuck since last night on this. 我正在研究这个项目,我想在单击signUp按钮后更新数据库,但是$ .post()无法正常工作,我找不到任何错误,因为甚至没有错误显示在Firebug中Firefox,请帮帮我,自昨晚以来,我一直对此感到困惑。

Am I doing any mistake, then please help me out to find those ? 我在做任何错误,然后请帮助我找出这些错误?

Here is my code, 这是我的代码,

part of my script.js 我的script.js的一部分

.............
.............
 $('#submit').click(function() {
    $.post("signup.php", function(data) {
        response = jQuery.parseJSON(data);
        alert(response.done);
    });
});

signup.php signup.php

<?php
    $json = array("done" => "1");
    echo json_encode($json);
?>

registration.php page registration.php页面

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"
     ..........
     ..........
     <input type="submit" class="btn btn-lg btn-info searchBtn signUpBtn wobble-skew" value="Sign Up" name="submit" id="submit">
</form>

In the js file i was alert to just checking whether post is responding or not, it it did then i have to pass the input's value using JSON 在js文件中,我很警惕,只是检查帖子是否响应,它确实做到了,然后我必须使用JSON传递输入的值

You need to disable the normal form submission: 您需要禁用普通表单提交:

$('#submit').click(function(e) {
    e.preventDefault(); // Prevent normal submission
    $.post("signup.php", function(data) {
        response = jQuery.parseJSON(data);
        alert(response.done);
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM