且构网

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

刷新部分页面(div)

更新时间:2023-02-11 13:18:41

使用Ajax进行此操作。通过ajax获取当前页面,但不是整个页面,只是服务器上的div。然后,数据将(再次通过jQuery)被放入相同的div中,并用新的内容替换旧内容。



相关函数:

http://api.jquery.com/load/ p>

eg

  $('#thisdiv')。 URL +'#thisdiv'); 

请注意,加载会自动替换内容。请确保在ID选择器之前包含空格。


I have a basic html file which is attached to a java program. This java program updates the contents of part of the HTML file whenever the page is refreshed. I want to refresh only that part of the page after each interval of time. I can place the part I would like to refresh in a div, but I am not sure how to refresh only the contents of the div. Any help would be appreciated. Thank you.

Use Ajax for this.

Build a function that will fetch the current page via ajax, but not the whole page, just the div in question from the server. The data will then (again via jQuery) be put inside the same div in question and replace old content with new one.

Relevant function:

http://api.jquery.com/load/

e.g.

$('#thisdiv').load(document.URL +  ' #thisdiv');

Note, load automatically replaces content. Be sure to include a space before the id selector.