1
我想創建一個表單,其中包含一個URL的操作。但它首先需要提交ajax,然後提交給action。阿賈克斯沒有提交提交
它應該給我發電子郵件(在newsletter.php內)。
<script type='text/javascript'>
$(function() {
$("#signup").on('submit', function(e, response) {
if (response.errors == false) {
$.ajax({
type : 'GET',
url : 'newsletter.php',
data: {
name : $('#os0').val(),
email: $('#os1').val()
},
success : function(data) {
$('#subscribe').submit();
},
error : function(XMLHttpRequest, textStatus, errorThrown) {
// error handling
}
});
return false;
}
return true;
});
});
</script>
HTML
<form name="signup" id="signup" action="" method="GET">
<input type="text" id="os0" name="Email" />
<input class="text" id="os1" type="text" name="cd_FULLNAME" />
<input type="Submit" name="Submit" id="subscribe" value="Subscribe" />
</form>
這將是無止境的循環。 – HaBo 2014-08-29 19:51:27
你的提交處理程序應該從哪裏得到一個名爲'response'的變量來自...? – CBroe 2014-08-29 19:51:38
什麼是在這裏做的「響應」?這將是'未定義'。檢查這個小提琴:http://jsfiddle.net/karthikr12/c2m09dsk/(有防止默認動作) – karthikr 2014-08-29 19:52:22