[英]Open dialog on ajax success call
我正在努力尋找一種成功的ajax事件后打開對話框窗口的方法。 目前,我正在使用jquery .html在div中插入一些html,但是我想做的是使用html創建對話框窗口,而不是使用名為div的標准。 這樣做的原因是因為值會更改,因此標准響應將不會執行。 這是可能嗎?
我的示例代碼中的div; #dialog-message,僅是示例。 謝謝
jQuery +對話框代碼
//Begin function to submit report form
$(function () {
$("#frmreport").submit(function () {
var send = $(this).serialize();
$.ajax({
type: "POST",
url: "/sample/admin/frm10010.php",
data: send,
dataType: "json",
success: function (msg) {
$("#confirm_department").hide();
$(function () {
$("#dialog-message").dialog({
modal: true,
buttons: {
Ok: function () {
$(this).dialog("close");
}
}
});
});
//alert('You have succesfully submitted your '
// + msg.dept + ' report. Thank you.');
//$("#report_result").html("You have succesfully
// submitted your report. Thank you."+"<br /><br />");
$("#formShow").hide();
$("#formImage .col_1 li").show();
$("#frmreport").get(0).reset();
}
});
return false;
});
});
// End function to submit report form
無需將對話框初始化包裝在$(function() {...});
功能。 這會將ready
事件監聽器附加到文檔,因此不需要,因為您已經包裝了所有內容: http : //api.jquery.com/jQuery/#jQuery3
嘗試將您的success
回調替換為:
function (msg) {
$("#confirm_department").hide();
$("#dialog-message").dialog({
modal: true,
buttons: {
Ok: function () {
$(this).dialog("close");
}
}
});
//alert('You have succesfully submitted your ' + msg.dept + ' report. Thank you.');
//$("#report_result").html("You have succesfully submitted your report. Thank you."+"<br /><br />");
$("#formShow").hide();
$("#formImage .col_1 li").show();
$("#frmreport").get(0).reset();
}
另外, dialog()
是jQueryUI的一部分,而不是基礎jQuery庫。 您需要導入兩個庫才能正常工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.