Reputation: 25
After submitting by AJAX, I'd like to have the form close. I looked up on Google and some old topics here, but I couldnt find anything! I have one function i javascript to show my forms and I have another one to ajax request, i think i should get the instance of open modal window and then close it, but im not sure.
Here is the code to show the form window
$(function (){
function handler() {
if (this.readyState == this.DONE) {
if (this.status == 200 && this.responseText != null) {
$("#modal").html(this.responseText);
return;
}
console.log('Something went wrong! Status = ' + this.status);
}
}
var client = new XMLHttpRequest();
client.onreadystatechange = handler;
$(document).ready(function () {
$(document).on('click','.showModal',function(event) {
client.open("GET", $(this).attr("href"),true);
client.send();
var dialog;
dialog = $("#modal").dialog({
autoOpen:true,
width: 400,
height: 450,
modal: true,
/*close: function () {
$("#modal").html('');
}*/
buttons: [{
text: "Cancelar",
click: function() {
dialog.dialog("close");
}
}],
close: function () {
$("#modal").html('');
}
});
return false;
});
});
});
Here is the code through which I'm sending data by AJAX, and trying to close the window with afterward:
$(function(){
$("#y").on('click',function(event){
event.preventDefault();
var id = $("input[name=id]").val();
var action = 'del';
$.post("album/ajax",{
action : action,
id : id
},
function(data){
if(data.response == true){
if(action == 'del') {
var table = $('#table');
table.find('tr').each(function(indice){
$(this).find('td').each(function(indice){
if($(this).text() == ''){
var valor = $(this).find('input[name=cod]').val();
if(valor == id){
$(this).closest('tr').remove();
/*var dialog;
dialog = $("#modal").dialog();
dialog.closest(".ui-dialog-content").dialog("close");
dialog.dialog("close");*/
}
}
});
});
}
} else {
alert("Nao foi possivel deletar!");
}
},'json');
});
});
Upvotes: 1
Views: 3098