【发布时间】:2014-08-15 20:59:47
【问题描述】:
通过 AJAX 提交后,我想关闭表单。我查了谷歌和一些老话题,但我找不到任何东西!我有一个功能我 javascript 来显示我的表单,我还有另一个功能来 ajax 请求,我想我应该获取打开模式窗口的实例然后关闭它,但我不确定。
这是显示表单窗口的代码
$(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;
});
});
});
这是我通过 AJAX 发送数据并尝试关闭窗口的代码:
$(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');
});
});
【问题讨论】:
-
我已经看过那里了,但没有人为我工作。我仍然有同样的问题。
标签: javascript jquery ajax forms jquery-ui