我正在嘗試構建訂閱表單。我無法在我的網站上運行PHP,並且我不希望用戶離開主站點訂閱通訊。我正在使用this example as server side。 如果您嘗試向您發送電子郵件,您將收到重定向,即使電子郵件已添加到mailchimp列表中,也會顯示錯誤消息。Ajax不顯示服務器響應
<div id="email">
<span>Your email..</span>
<form action="http://simondahla.com/jolliassets/notify.php" id="notify" method="POST">
<input type="text" placeholder="[email protected]" name="email" id="address" data-validate="validate(required, email)"/>
<span>We'll never spam or give this address away</span>
<button type="submit">»</button>
</form>
<span id="result"></span>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#notify').submit(function() {
var action = $(this).attr('action');
$.ajax({
url: action,
type: 'POST',
data: {
email: $('#address').attr('value')
},
success: function(data){
$('#result').html(data).css('color', 'green');
},
error: function() {
$('#result').html('Sorry, an error occurred.').css('color', 'red');
}
});
});
});
</script>
[途徑可能重複繞過同源政策](http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy) – Quentin
Wher e是實際添加到mailchimp的代碼? –