(按钮 || 输入) type=submit - jQuery AJAX 中 $_POST 变量缺少值

Jac*_*vis 1 html javascript php ajax jquery

我有登录表单,其中有两个按钮 - “登录”和“忘记密码?” 我需要检查用户单击了哪个按钮。

<form id="loginForm">
<div class="login-error" id="login-error"></div>
<input type="text" id="email" name="email">
<input type="password" id="password" name="password">
<input type="submit" name="submit" value="Login">
<button type="submit" name="submit" value="Forgot password?">Forgot password?</button>
</form>
Run Code Online (Sandbox Code Playgroud)

var_dump($_POST) 说:

array(2) { ["email"]=> string(0) "" ["password"]=> string(0) "" }
Run Code Online (Sandbox Code Playgroud)

我正在尝试两种方式(输入类型=提交和按钮类型=提交),但它们都没有发送“提交”值。

(我使用jquery ajax)

 $("#loginForm").click(function(){
    /* Stop form from submitting normally */
    event.preventDefault();

    /* Get some values from elements on the page: */
    var values = $(this).serialize();

    /* Send the data using post and put the results in a div */
    $.ajax({
        url: "login.php", /* here is echo var_dump($_POST); */
        type: "post",
        data: values,
        success: function(data){
            $("#login-error").html(data);
        },
        error:function(){
            $("#result").html('There is error while submit');
        }
    });
});
Run Code Online (Sandbox Code Playgroud)

请问您知道问题出在哪里吗?我知道,有很多关于按钮价值的话题,但对我来说没有任何作用。我也尝试过这个例子: http://www.w3schools.com/tags/tryit.asp? filename=tryhtml_button_value2

Cod*_*ous 5

.serializeArray() 或 .serialize() 方法使用成功控制的标准 W3C 规则来确定应包含哪些元素;特别是该元素不能被禁用并且必须包含名称属性。由于未使用按钮提交表单,因此不会序列化提交按钮值。文件选择元素中的数据未序列化。

参考..

http://api.jquery.com/serialize

http://api.jquery.com/serializeArray

jQuery serializeArray 不包括单击的提交按钮