如何使用JQuery和PHP使用POST提交attr值和表单值?

Kyl*_*ley 4 html javascript php forms jquery

所以我有一个带有输入框的表单和一个div在点击时突出显示的类型.我试图让它提交属性和"#email"值并通过PHP通过电子邮件发送给我.

这是我的HTML:

<form id="form" name="form" class="custompurchase" action="custom.php" method="post">
    <input type="email" id="email" name="email" maxlength="40" class="textbox2" placeholder="Email address" required/>
    <a class="customoption storage" onclick="activate(this, 'storage');" data-name="500GB HDD">
        ...
    </a>
    <a class="customoption storage" onclick="activate(this, 'storage');" data-name="1TB HDD">
        ...
    </a>
    <a class="customoption storage" onclick="activate(this, 'storage');" data-name="2TB HDD">
        ...
    </a>
</form>
Run Code Online (Sandbox Code Playgroud)

这是我的JQuery:

$(function() {
    var form = $('#form');
    $(form).submit(function(event) {
        event.preventDefault();
        var email = $("#email").val();
        var storage = $(".customoptionactive.storage").attr("data-name");
        $.ajax({
            type: "POST",
            url: $(form).attr("action"),
            data: email, storage
        })
        .done(function(response) {
            ...
        });
    });
});
Run Code Online (Sandbox Code Playgroud)

最后我的PHP:

<?php
    $emailto = "purchases@prismpc.net";
    $subject = "Custom PC";
    $email = $_POST['email'];
    $storage = $_POST['storage'];
    $entire = "Email: ".$email."\n"."Storage: ".$storage;
    mail($emailto, $subject, $entire);
?>
Run Code Online (Sandbox Code Playgroud)

但是,当我看到电子邮件时,这就是我得到的:

Email:
Storage:
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?我需要设置dataType吗?非常感谢你的回答!

编辑:与类似问题不同,因为它是一个简单的语法错误.

rou*_*lie 5

改变你的data选择$.ajax

 data: email, storage
Run Code Online (Sandbox Code Playgroud)

 data: {email:email, storage:storage}
Run Code Online (Sandbox Code Playgroud)