/ / जावास्क्रिप्ट Django में डायलॉग की पुष्टि करें - जावास्क्रिप्ट, jquery, django

Django में जावास्क्रिप्ट की पुष्टि संवाद - जावास्क्रिप्ट, jquery, django

मेरे पास एक Django रूप है। और मुझे फॉर्म सबमिट पर पुष्टि / रद्द संवाद की आवश्यकता है। A को jQuery से POST डेटा भेजने का विचार था ... लेकिन क्या यह जावास्क्रिप्ट संवाद को मिडलवेयर के रूप में उपयोग करने का एक तरीका है?

उत्तर:

जवाब के लिए 2 № 1

अपने Html में अपनी आवश्यकता के अनुसार bellow कोड जोड़ें

<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>

यहाँ आपको अजाक्स ज्ञान की आवश्यकता है और यह सुनिश्चित करना बहुत आसान है कि आप ऐसा करते हैं :)