jQuery.post没有POSTing

时间:2013-11-20 12:09:26

标签: php jquery email

我正在尝试使用jQuery将数据发布到emailus.php脚本。

这是脚本部分:

<script>
jQuery(document).ready(function(){

    jQuery('#submitt').click(function(){
        jQuery.post("/emailus.php", jQuery("#mycontactform").serialize(),  function(response) {

            jQuery('#success').html(response);

        });
        return false;

    });

});
</script>

以下是使用的HTML:

<form action="" method="get" id="mycontactform" >
<label for="name">Your Name:</label><br />
<input type="text" name="name"  class="cleann" /><br />
<label for="email">Your Email:</label><br />
<input type="text" name="email"  class="cleann" /><br />
<label for="message">Your Message:</label><br />
<textarea name="message" class="cleann" rows="7"></textarea><br />
<input type="button" value="send" id="submitt" class="cleannsubmit" /><div id="success" style="color:green;"></div>
</form>

这是php脚本:

<?php

// Here we get all the information from the fields sent over by the form.
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];

$to = 'nohanada@gmail.com';
$subject = 'Fortrove Contact';
$message = 'FROM: '.$name.' Email: '.$email.'Message: '.$message.'\n\nItem:'.$itemname;

print_r($_POST);
if($name && $email && $message){
    if (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){
        mail($to, $subject, $message); 
        echo "Your email was sent!"; 
    }
    else echo "<span style='color:red'>Invalid email format.</span>";
}
else echo "<span style='color:red'>Please fill all fields</span>";
?>

问题是它没有将实际字段POST到php脚本。我做错了什么?

1 个答案:

答案 0 :(得分:0)

您已将mycontactform置于product_addtocart_form内,这是不允许的原因,因此浏览器似乎正在重新调整mycontactform