我无法通过subscribe.php文件使用Jquery提交以下表单,并从PHP文件中获取响应。
我正在尝试将表单提交到Mailchimp上的订阅列表,并希望在html页面上显示通过subscribe.php($ result)从Mailchimp收到的响应消息。我不习惯PHP,并想知道如何解决这个问题。
我得到以下内容:
post('lists/0b65107073/members', array( 'email_address' => $_POST["email"], 'status' => 'subscribed' )); if($result){ $status = $result["status"]; if($status == "subscribed"){ echo "Great! We will keep you updated on our progress."; } else{ echo "Oops! Something went wrong. Please try again."; } } ?>
附加到#SubscribeMessage div而不是获取提交数据的响应。此外,数据未按预期提交给mailchimp。我不确定这是jquery还是php方面的问题。
<form id="SubsribeForm1">
<input id="emailAdd" name="email" type="text" placeholder="Hinterlasse Deine Email…" class="col-md-8 EmailInput" />
<button id="SubscribeEmail" class="EmailSubmit" type="submit">Einreichen</button>
<div id="SubscribeMessage"></div>
</form>
<script>
$(document).ready(function(){
$('#SubscribeEmail').click(function(e) {
e.preventDefault();
$.ajax({
type : 'POST',
url : 'subscribe.php',
data: {
email : $('#emailAdd').val()
},
success:function (data) {
$("#SubscribeMessage").append(data);
}
});
});
});
</script>
subscribe.php
<?php
require("_mc.php");
use \DrewM\MailChimp\MailChimp;
$MailChimp = new MailChimp('6385e94cf70076a289c1dyd656920f49-us13');
$result = $MailChimp->post('lists/0b6510i85f/members', array(
'email_address' => $_POST["email"],
'status' => 'subscribed'
));
if($result){
$status = $result["status"];
if($status == "subscribed"){
echo "Great! We will keep you updated on our progress.";
}
else{
echo "Oops! Something went wrong. Please try again.";
}
}
?>