我正在使用jQuery UI将ASP.NET MVC 5局部视图渲染为空div:
$(document).ready(function () {
$(".SiteName").on("click", function (event) {
event.preventDefault();
var siteName = $(this).data("sitename");
//alert(siteName);
$.ajax({
url: "/EtlLog/ListSiteJobs?SiteDescription=" + encodeURIComponent(siteName),
type: "GET",
})
.done(function (result) {
$("#ListSite").html(result).dialog("open");
});
});
})
点击后检查ListSite div,我看到它充满了预期的结果,但是我得到了一个jQuery UI错误:
Uncaught Error: cannot call methods on dialog prior to initialization; attempted to call method 'open'
我尝试过.ready()的各种组合,甚至嵌套在用于.dialog()的div中渲染的div。必须查看有关此错误的每个问题,但仍未找到解决方案。
答案 0 :(得分:1)
首先需要“设置”对话框,然后open
。尝试:
$(document).ready(function () {
$(".SiteName").on("click", function (event) {
event.preventDefault();
var siteName = $(this).data("sitename");
//alert(siteName);
$("#ListSite")
.load("/EtlLog/ListSiteJobs?SiteDescription=" + encodeURIComponent(siteName))
.dialog({autoOpen:true})
});
})
P.S:我冒昧地使用load()
来缩短你的代码。