我有一个 Django 表单。我需要在表单提交时有一个确认/取消对话框。 A 有一个从 jQuery 发送 POST 数据的想法...但是这是一种使用 javascript 对话框作为中间件的方法吗?
最佳答案
根据您的需要在 Html 中添加以下代码
<form><input type="submit" value="Submit" id="confirm"/> </form>
和确认对话框的 jQuery 代码
<script>
jQuery("#confirm").click(function(){
$("<div></div>").appendTo('body')
.html('<div><h3> write your message for confirm dialog</h3></div>')
.dialog({
title: "Confotm Dialog" ,
width:500, height:300,
modal:true,
resizable: false,
show: { effect: 'drop', direction: "left" },
hide:{effect:'blind'}
buttons: {
Yes: function() {
jQuery.ajax({
type:"POST", //post data
data:{'key':key}, //if you want to send any data to view
url:'/get_viewerModal/' // your url that u write in action in form tag
}).done(function(result){
alert("am done") //this will executes after your view executed
})
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
});
<script>
这里你需要 ajax 知识,而且它非常容易使用,我确信你会这样做:)
关于Django 中的 JavaScript 确认对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14480492/