當彈出確認消息並且用戶單擊確定時,我想從窗體中的隱藏輸入類型發送一個id。現在我甚至不能在沒有確認彈出框的情況下編碼,沒有錯誤,只是刷新而沒有任何反應。您可能會想,爲什麼我需要確認將商品添加到購物車中,但這是因爲我還需要稍後從數據庫中刪除商品。如何在確認彈出窗口後使用ajax/jquery發佈數據
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#add').click(function(){
var id = $("#get_id").val()
$.confirm({
'title' : 'Delete Confirmation',
'message' : 'You are about to delete this User.Continue?',
'buttons' : {
'Yes' : {
'action': function(){$a.ajax({
url: 'http://localhost/com/index.php/shopping_basket/view_basket',
type: 'POST',
data: { id: id },
success: (function(){
alert('added' + id);
});
}
},
'No' : {
'action': function(){} // Nothing to do in this case. You can as well omit the action property.
}
}
});
});
});
</script>
形式
<form id="basket" method="post" action="">
<input type="hidden" id="get_id" value="<?php echo $id ?>">
<input type="submit" id="add" value="Add">
</form>
順便說一句什麼在使用window.location.href送東西,而不是這有什麼區別?
'AJAX'在瀏覽器和'web服務器'之間使用'異步數據傳輸'(HTTP請求),允許網頁從服務器而不是整個頁面請求少量信息',而不需要'重新加載網頁' 。 – Ranjith 2013-04-05 13:18:07