我正在使用 AJAX (jQuery) 向 PHP 脚本提交表单。
这是JavaScript:
// Validate form fields
$(function () {
//Check to see if email is not empty
if (email == "") {
$("label#email_error").show();
$("input#email").focus();
return false;
}
var dataString = 'firstname=' + firstname + '&email=' + email + '&lastname=' + lastname;
$.ajax({
type: "POST",
url: "/",
data: dataString,
success: function () {
var counter = <?php echo($counter['count'] + 1); ?>
counter = numberWithCommas(counter);
$('#counter').html(counter);
$('#contact_form').html("<div id='message'></div>").fadeIn(1500, function () {
$('#message').html("<h2>Thanks " + (firstname) + "!</h2>").append("<p>We will be in touch soon.</p>");
});
}
});
return false;
});
在 PHP 脚本中,我有以下代码:
if (!empty($_POST)){
$adestra = $this->adestraAction('contact.create' , array('1', array('1.email' => $_POST['email'] , '1.forename' => $_POST['firstname'] , '1.surname' => $_POST['lastname'],'1.source' => 'signupbox' )));
$add = $this->addToListAction($adestra, $magazineID);
}
$_POST 变量似乎没有被设置。有人可以帮忙吗?