Created
August 23, 2013 17:08
-
-
Save dubrod/6321687 to your computer and use it in GitHub Desktop.
Run a PHP or jQuery Function after jQuery UI Dialog Confirmation. You can read the supporting article at : https://www.revitalagency.com/blog/run-a-php-or-jquery-function-after-jquery-ui-dialog-confirmation/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
$(function() { | |
//run function after jquery dialong confirm | |
//step 1 - the action | |
$(".deleteBtn").click(function(e) { | |
e.preventDefault(); | |
pid = $(this).attr("title"); // the id of the photo i want to delete | |
//console.log($(this).attr("title")); // check you get it first | |
$('#dialog-confirm').dialog('open'); | |
}); | |
//step 2 - the dialog modal | |
$( "#dialog-confirm" ).dialog({ | |
resizable: true, | |
height:270, | |
modal: true, | |
autoOpen:false, | |
buttons: { | |
"Delete": function() { | |
//console.log(pid + " made it to dialog"); // make sure our id makes it this far | |
deletePhoto(pid); // run delete photo function | |
$( "table#" + pid ).fadeOut("slow"); // fadeOut our table details for the photo b/c we just deleted it | |
$( this ).dialog( "close" ); | |
}, | |
Cancel: function() { | |
$( this ).dialog( "close" ); | |
} | |
} | |
}); | |
//step 3 - php function | |
function deletePhoto(pid){ | |
//console.log(pid + " made it to function"); // make sure our id makes it this far | |
$.ajax({ | |
type: "POST", | |
url: "processes/delete-photo.php", | |
data: { id: pid } | |
}).done(function( msg ) { | |
//no message bc we did a fadeOut | |
//var msg would show any errors from our php file | |
}); | |
}; | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment