Asp.net mvc 加载带有ajax调用内容的div后触发事件
我有一个场景,在ajax回调事件中将html加载到div中。我的目标是在加载主内容后,在新加载的div上附加另一个div。主要问题是加载了大量html,我必须等到加载完成 基本步骤如下Asp.net mvc 加载带有ajax调用内容的div后触发事件,asp.net-mvc,jquery,Asp.net Mvc,Jquery,我有一个场景,在ajax回调事件中将html加载到div中。我的目标是在加载主内容后,在新加载的div上附加另一个div。主要问题是加载了大量html,我必须等到加载完成 基本步骤如下 @using (Ajax.BeginForm ( Model.PostAction, Model.PostController, null, new AjaxOptions() { OnSuccess = "contentLoadSuccess", OnFailure = "con
@using (Ajax.BeginForm
(
Model.PostAction,
Model.PostController,
null,
new AjaxOptions() { OnSuccess = "contentLoadSuccess", OnFailure = "contentLoadFailure" },
new { id = "reportBase_frmViewer", name = "reportBase_frmViewer" })
)
{
...
}
function contentLoadSuccess(ajaxContext) {
showWaitIndicator(false);
if (ajaxContext.Format == null)
//If the format is not there then the server reponded but the an unhandled exception was caught and thrown
//the content will be the user friendly version
setReportContent(ajaxContext);
else {
if (ajaxContext.Format == "HTML") {
//If the format is HTML then it is already in the result, inject it into the content container
showWaitIndicator(true);
updatePageNumber(ajaxContext.PageNumber, ajaxContext.TotalPageNumber);
setReportContent(ajaxContext.HTMLContent);
} else
//Export option is used. The render link has a url friendly format to start the file download
window.location.href = ajaxContext.RenderLink + "&format=" + ajaxContext.Format;
}
}
function setReportContent(content) {
$("#reportContent").html(content);
$("#toggleToolbar").appendTo("#reportContent");//<- Does not work content takes to long and will overwrite appended div
$("#reportContent").show();
}
$(document).ready(function () {
//This does not work either
$("#reportContent").load(function (e) {
$("#toggleToolbar").appendTo("#reportContent");
$("#toggleToolbar").show();
});
});
$("#reportContent").on("load", function (event) {
alert("This does not work either");
$("#toggleToolbar").appendTo("#reportContent");
});
@使用(Ajax.begin)
(
模型.PostAction,
Model.PostController,
无效的
新的AjaxOptions(){OnSuccess=“contentLoadSuccess”,OnFailure=“contentLoadFailure”},
新的{id=“reportBase\u frmViewer”,name=“reportBase\u frmViewer”})
)
{
...
}
函数contentLoadSuccess(ajaxContext){
showWaitIndicator(假);
if(ajaxContext.Format==null)
//如果该格式不存在,则服务器将进行响应,但捕获并引发了未处理的异常
//内容将是用户友好的版本
setReportContent(ajaxContext);
否则{
if(ajaxContext.Format==“HTML”){
//如果格式是HTML,那么它已经在结果中,将其注入内容容器
showWaitIndicator(真);
updatePageNumber(ajaxContext.PageNumber、ajaxContext.TotalPageNumber);
setReportContent(ajaxContext.HTMLContent);
}否则
//使用导出选项。呈现链接具有url友好格式以开始文件下载
window.location.href=ajaxContext.RenderLink+“&format=“+ajaxContext.format;
}
}
函数setReportContent(内容){
$(“#reportContent”).html(内容);
$(“#toggleToolbar”)。请附加到(“#reportContent”);//尝试使用超时
function setReportContent(content) {
$("#reportContent").html(content);
setTimeout(function(){
$("#toggleToolbar").appendTo("#reportContent");//<- Does not work content takes to long and will overwrite appended div
$("#reportContent").show();
}, 200);
}
函数setReportContent(内容){
$(“#reportContent”).html(内容);
setTimeout(函数(){
$(“#toggleToolbar”).appendTo(“#reportContent”)//