I am using js confirmation. I want to make it more beautiful with jquery UI.
Using js confirmation:
$("a.delete").click(function() {
el = $(this);
if (confirm("Are you sure you want delete the data?")) {
$.ajax({
url : $(this).attr("href"),
type : "GET",
dataType : 'json', //The requested response in JSON format
success : function(response) {
if (response.status == 1) {
loadData();
$("#divFormContent").load("ajax.php?module=test&action=form_test");
$("#divFormContent").hide();
$("#btn_hide").hide();
// alert("The data successfully deleted!");
} else {
alert("Data failed in the clearing!");
}
}
});
}
return false;
});
Can anybody tell me how can I change it using jquery UI confirmation?
First, you need to create the element which will be displayed. Sample html:
The element will be automatically hidden when you call
.dialog()on it passing theautoOpen: falseparameter. Do it inside the DOM ready handler preferably.jQuery UI’s dialog boxes are asynchronous, they won’t freeze the function and wait for a response as the
confirmprompt does. Instead, you have to wrap your function inside the “Yes” confirmation button’s callback.When you need the dialog then, just call
$("#dialog-confirm").dialog("open");.And to finish,
thiswill no longer reference the clicked element when you move your function from the click handler to the dialog’s callback handler. I used.datato store the clicked$(this).attr('href')in the#dialog-confirm‘s data and retrieve it for the Ajax call.Here’s the code:
jsFiddle