jQuery:在继续之前等待回调返回
我有一个页面,当单击各种内容时,它使用相当多的 ajax 来加载其内容,现在我正在努力通过读取 url 中传入的哈希值来链接到页面的不同部分,作为一种小路。我想我可以浏览传入的哈希的不同部分,并使用 jQuery 的 .trigger() 触发右键单击。这样做的问题是,在该部分的内容实际加载之前(因为它是通过ajax加载的),下一秒触发器将被调用,这意味着它试图触发的东西不存在。在我使用下一个触发器之前,有没有一种好方法可以设置某种标志或某些东西来了解所有回调何时完成并且所有内容都已加载?或者我以完全错误的方式处理这个问题?只是寻找一些关于如何完成此任务的一般策略。
I have a page which uses a fair bit of ajax to load its contents when various things are clicked and right now I am working on being able to link to the different parts of the page by reading the incoming hashes in the url as a sort of path. I figured that I could just go through the different sections of the hash that comes in and trigger the right clicks using jQuery's .trigger(). The problem in doing this is that the next second trigger will be called before the contents of the section is actually loaded (as it is being loaded via ajax) meaning the thing it is trying to trigger doesn't exist. Is there a good way to set sort of a flag or something to know when all the callbacks complete and all of the content is loaded before I use the next trigger? Or am I approaching this the completely wrong way? Just looking for some general strategy on how to get this done.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您想要创建一个
成功
回调。顾名思义,一旦加载成功完成,就会执行此代码。请参阅 http://api.jquery.com/jQuery.ajax/
You want to create a
success
callback. As the name implies, this code will be executed once your load has completed successfully.See "Callback Function Queues" on http://api.jquery.com/jQuery.ajax/
如何使用
来等待请求加载
how about using the
to wait until request is loaded