Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
193 views
in Technique[技术] by (71.8m points)

javascript - 刷新页面的一部分(div)(Refresh Part of Page (div))

I have a basic html file which is attached to a java program.(我有一个附加到Java程序的基本html文件。)

This java program updates the contents of part of the HTML file whenever the page is refreshed.(每当刷新页面时,此java程序都会更新HTML文件的部分内容。) 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 .(我可以将要刷新的部分放在div ,但是我不确定如何仅刷新div的内容。) Any help would be appreciated.(任何帮助,将不胜感激。) Thank you.(谢谢。)   ask by user760220 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use Ajax for this.(为此使用Ajax。)

Build a function that will fetch the current page via ajax, but not the whole page, just the div in question from the server.(构建一个函数,该函数将通过ajax获取当前页面,而不是整个页面,仅从服务器中获取有问题的div。) The data will then (again via jQuery) be put inside the same div in question and replace old content with new one.(然后,数据(再次通过jQuery)将放入相关的div中,并用新内容替换旧内容。) Relevant function:(相关功能:) http://api.jquery.com/load/(http://api.jquery.com/load/) eg(例如) $('#thisdiv').load(document.URL + ' #thisdiv'); Note, load automatically replaces content.(注意,加载会自动替换内容。) Be sure to include a space before the id selector.(请确保在ID选择器之前包含一个空格。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...