javascript 只重新加载网页的一部分

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12399952/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 16:06:17  来源:igfitidea点击:

Only reload a part of a web page

javascriptjqueryajax

提问by Shailendra

I have a page in which a user is asking a question after watching video. I want to update the number of questions asked as soon as any user asks question. I do not want to reload the whole page. I only want to update that specific div which is containing all questions.

我有一个页面,用户在观看视频后在其中提问。我想在任何用户提出问题时立即更新提出的问题数量。我不想重新加载整个页面。我只想更新包含所有问题的特定 div。

回答by Tadeck

You can use jQuery.load()for this.

您可以jQuery.load()为此使用。

For example, wherever you want to refresh some div with id=questions, you do this:

例如,无论您想在何处使用 id= 刷新某个 div questions,都可以这样做:

jQuery('#questions').load('/some_url #questions > *');

回答by Esben Skov Pedersen

You add a page to you server which returns only your questions.

您向服务器添加一个页面,该页面仅返回您的问题。

e.g. your full page contains

例如你的整页包含

<div id="questions"></div>

then you design a page /questions.php on your server which returns only what is supposed to be in that div

然后你在你的服务器上设计一个页面 /questions.php,它只返回应该在那个 div 中的内容

with jquery.load you fill the questions div

使用 jquery.load 填写问题 div

<script>$(function(){  $("#questions").load("/questions.php")  })</script>