且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jquery html 回调

更新时间:2021-09-10 08:49:56

html() 是一个同步操作.DOM 的实际更新取决于您的 html 内容是什么.如果您有 标签,它们将需要一些时间来加载.html() 后面的下一条语句应该立即看到新的 html 内容.

html() is a synchronous operation. The actual updating of the DOM depends on what your html content is. If you have <img> or <iframe> tags, they will take time to load. The next statement following the html() should immediately see the new html contents.

你是说 load() 吗?

[Edit] 根据您的评论,可能是您的 $.ajax 失败了.不是 html().尝试将故障处理程序附加到 ajax 调用并从那里重试?虽然,如果您的服务器端代码以 200 代码静默失败,则不会调用失败事件.在这种情况下,您可以在将 html 值设置为元素之前对其进行验证.

Based on your comment, it is probably your $.ajax failing. Not html(). Try attaching a failure handler to ajax call and retry from there? Although, if your server side code silently fails with a 200 code, the failure event doesn't get called. In that case, you can validate the html value before you set it to the element.