jQuery在异步回发时不执行document.ready [英] JQuery doesn't perform document.ready on async postback

查看:84
本文介绍了jQuery在异步回发时不执行document.ready的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个用户控件,该用户控件在document.ready中执行了一些jquery来处理分页解决方案.但是,它需要定位的页面之一,用户控件开始时不可见,并且使用异步回发来显示它.

我发现这阻止了ready()中的代码被执行.我找到了一个有用的博客,该博客将以下代码段添加到了主页上:

I''ve created a user control that does some jquery in document.ready to handle a paging solution. However, one of the pages it needs to be located, the user control isn''t visible to start with and an async postback is used to display it.

I''ve discovered that this prevents the code from within ready() to be executed. I found a useful blog which gave the following snippet to be added to the main page:

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
     function EndRequestHandler(sender, args) {
         if (args.get_error() == undefined) {
                alert('async postback event caught');
         }
     }



这意味着我现在可以赶上异步回发的结束了.但是,我仍然看不到如何调用用户控件中包含的代码(Web开发不是我的主要技能领域).谁能指出我正确的方向?

TIA

Dave



which means I can now catch the end of the async postback. However, I still can''t see how to call the code contained within the user control (web dev isn''t my main skill area). Can anyone point me in the right direction?

TIA

Dave

推荐答案

jQuery是传统JavaScript的一种包装.它可以用作Java脚本来捕获事物.
好像您在谈论捕获UpdatePanel异步更新.

您可以通过以下方式捕获更新面板的异步更新:
jQuery is a sort of wrapper over a traditional JavaScript. It can be used as Javascripts are used to trap things.
Looks like you are talking of trapping an UpdatePanel async update.

You can catch the async update of update panel as:
function EndRequestHandler(sender, eArgs) 
{            
   /*
   1. Alert/Message if any after update
   2. Error handling if any
   3. Scroll position set again
   4. Focus/UI update if any
   */
   //Example
   if (eArgs.get_error() == null)
   {
      // Do all the stuffs needed after update through JavaScript here. 
      //1. Alert / Show window / Show Dialog
      //alert("Update was successful");
      //2. Page Controls accessed via JavaScript
      document.getElementById("lblTest").innerText = "Update Successful";
      //3. Page scrolls can be set if needed
      //Set Scroll Position
   }
   else
   {
      // There was an error in the update panels update 
      // caught here and message displayed via JavaScript               
      document.getElementById("lblTest").innerText = 
              "There was an error in update:"+eArgs.get_error().message;
   }
} 


有关详细信息,请查看本文: Ajax更新后(通过更新面板)对页面控件的JavaScript访问 [ ^ ]


For details, have a look at this article: JavaScript Access to Page Controls after Ajax Update (via Update Panel)[^]


当然不是,文档也不会像..
那样被重新处理. 您必须使用async函数的成功方法:执行异步完成后要执行的代码..


of course it doesnt, the document doesnt get re-processed like..
u gotta use a success: of the async function to do your code that u wanna do when the async is finished..
i.e.

var xhr =


.ajax({ ajaxrequiredarguements...... success: function( data, status ) { :: Call your method in here :: }, end.... });
.ajax({ ajaxrequiredarguements...... success: function( data, status ) { :: Call your method in here :: }, end.... });


这篇关于jQuery在异步回发时不执行document.ready的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆