AJAX reload div after complete

时光毁灭记忆、已成空白 提交于 2019-12-02 04:13:34

You cannot 'reload a div'. A div is just a single element on an entire webpage, and on its own it has no URL it was loaded from, so it cannot be reloaded. You can set/replace the contents of a div with an Ajax call, but that's definitely not 'reloading' - you'd need to explicitly define the URL to load its new content from.

If you want to explicitly replace a div's contents by loading it from a remote URL, you should use Request.HTML instead of Request.JSON, and supply the element (or its ID) as the update parameter:

  • update - (element: defaults to null) The Element to insert the response text of the Request into upon completion of the request.

If you are just looking to replace the contents of an element without remote loading, you can simply do:

$('id-of-div').set('text', 'Text to be placed inside the element');

Or:

$('id-of-div').set('html', '<p>HTML ending up <em>inside</em> the div</p>');

Or build an entire subtree as you did with the new Element call already.

As for the secondary question: location.reload() is just shorthand for window.location.reload() so yes, it will reload the entire page (or frame). It can because a window or frame actually has a location it was loaded from.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!