ajax回调后ascx页面中的$(document).ready
我在这里的设置遇到了一些问题,我有一个 .ascx
文件列表,它们在控制器本身的计算方面都执行不同的任务。 因此,在我的 .aspx
页面上,我单击 Ajax.ActionLink()
,这将根据我的项目呈现特定的 .ascx
文件。点击。 在该 .ascx
中有 1-3 个事件,将触发其中 2 个是 onclick
事件,1 个是 onload
事件。 onclick 事件更容易使用,因为我可以直接在控件事件中对其进行硬编码,如下所示 onclick="$("#toggleMe3").slideToggle("slow ");"
并且 onload
必须在加载 .ascx
时运行,我正在 $(document).ready(function 中测试它(){});
调用,这在 .aspx
页面中工作正常,但一旦我尝试将其添加到 .aspx
页面中,它就不起作用了。 t 加载并且它的理想情况是它可以工作,但我不知道为什么不可以。 事实上,如果我直接插入 .ascx
页面,脚本标记中的任何内容都不起作用,它们只有在硬编码到控件的事件中才起作用,至少其中一些是这样; onload
和 onprerender
不会触发。
I'm having a little problem with this setup here I have a list of .ascx
files and they all do different tasks in terms of calculations to the controller itself. So on my .aspx
page I click on an Ajax.ActionLink()
and this will render that specific .ascx
file based on the item I clicked. Within that .ascx
are 1-3 events that will fire 2 of them are onclick
events and 1 is onload
. The onclick
event(s) are easier to work with in terms of I can hardcode it directly in the controls event like so onclick="$("#toggleMe3").slideToggle("slow");"
and the onload
must run when the .ascx
is loaded i was testing this in a $(document).ready(function(){});
call, this works fine in the .aspx
page but as soon as I try adding it into the .aspx
page it doesn't load and its ideal that this works but I have no idea why not. In fact nothing in the script tags work if I insert directly into the .ascx
page they only work if hardcoded into the control's events, well some of them at least; the onload
and onprerender
don't fire.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我遇到了同样的问题,在 $(document).ready 中指定的部分回发脚本未执行后。 我在这里找到了解决方案 MSDN - PageRequestManager Class
看起来像添加如下脚本解决了问题
I had the same problem, after partial postback script specified in $(document).ready was not executed. I found solution here MSDN - PageRequestManager Class
Looks like adding a script like below fixes the issue
我已经成功地在通过 XHR 加载的部分中使用 $(document).ready 。 您通过 XHR 加载的视图是否会抛出 JavaScript 异常? 或者它们是否包含格式错误的 HTML?
我通常在通过 Ajax 加载的部分的底部有我的 $(document).ready 方法,比如......
I've had success using $(document).ready in my partials that get loaded via XHR. Are the views that you're loading via XHR throwing JavaScript exceptions? Or do they contain malformed HTML?
I typically have my $(document).ready method at the bottom of my partial that I load via Ajax, like...
我很难理解你的问题……但事情就这样了。
如果您使用 AJAX 调用加载日期,则 $(document).ready() 事件将不会触发 - 因为页面已经加载。 您现在只是加载更多数据。
如果您已经知道将出现的控件,请预加载 JavaScript,但不要仅使用单击事件处理程序进行绑定,而是使用实时处理程序。
那么
就会变成抱歉。
如果这不是您想要的,
I had a hard time understanding your question...but here it goes.
If you are loading date using AJAX calls, the $(document).ready() event will not fire -- because the page was already loaded. You are just loading more data now.
If you already know the controls what will apear, pre-load the JavaScript, but instead of just binding using the click event handler, use the live handler.
so
turns into
Sorry if this isn't what you were looking for.