$(document).ready()未针对Ajax加载的内容执行 [英] $(document).ready() not executed for ajax loaded content

查看:190
本文介绍了$(document).ready()未针对Ajax加载的内容执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在返回的部分页面中不执行document.ready的原因可能是什么? 它可以正常工作2次,但在第3次更新html之后没有任何反应:

What could be reasons not to execute document.ready within returned partial page? It works fine 2 times, but on 3rd time nothing happens after update of html:

alert(html);
alert($(PopUpItem));
$(PopUpItem).html(html);
alert('in set popup html completed'); 

我已执行所有警报,PopupItem和html具有正确的值. 我正在使用JQuery通过$ .post执行服务器调用.

I have all alerts executed, PopupItem and html has correct values. I am using JQuery to execute server call by $.post.

此外,如果发生某些语法错误,我是否可以使用错误处理程序来捕获?

Also, Can I have error handler to catch if some syntax error happened?

推荐答案

在返回的AJAX中,您不需要$(document).ready()调用. DOM已经加载.像这样简单的事情就可以解决问题:

Within your returned AJAX, you shouldn't need a $(document).ready() call. The DOM has already been loaded. Something simple like this should do the trick:

<script type="text/javascript">
// Do something here.
</script>

这篇关于$(document).ready()未针对Ajax加载的内容执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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