我使用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可變因素似乎並沒有被得到設定。任何人都可以幫忙嗎?
你可以發佈ajax查詢嗎?或者在你的php文件中,如果你打印post變量,你會得到什麼? <?php print_r($ _ POST);?> – 2012-08-06 14:21:27
你可以發佈jQuery代碼嗎?也許它正在做一個GET請求,但即使沒有,看到代碼將有所幫助 – 2012-08-06 14:22:38
當然,ajax查詢是: – richelliot 2012-08-06 14:23:12