jQuery 如何使用jquery重新加载div?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8983225/
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-08-27 11:22:33  来源:igfitidea点击:

How to reload div using jquery?

jquery

提问by Lan

I want to reload only the div without reloading page.

我只想重新加载 div 而不重新加载页面。

回答by Hemant Metalia

you question is vast scoped but you can try follwing Ajax will be do your requirement e.g. without reloading page.

您的问题范围很广,但您可以尝试以下 Ajax 将满足您的要求,例如无需重新加载页面。

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
var auto_refresh = setInterval(
function ()
{
$('#load_tweets').load('record_count.php').fadeIn("slow");
}, 10000); // refresh every 10000 milliseconds

<body>
<div id="load_tweets"> </div>
</body>

</script>


<div id="loaddiv">
</div>

Now finally you need to write the code for the file “reload.php” which will extract the contends from the other page or it also may contain the code to read the data from the database depending upon requirement. here i am going to read a small content from another site. you can copy , paste the code and save it as the filename “reload.php”. in the same folder that contains the source code.

现在最后你需要为文件“reload.php”编写代码,它将从另一个页面提取竞争,或者它也可能包含从数据库读取数据的代码,具体取决于需求。在这里,我将阅读另一个网站的一小部分内容。您可以复制、粘贴代码并将其保存为文件名“reload.php”。在包含源代码的同一文件夹中。

echo"<img src='http://www.nepalstock.com/datanepse/realindex.php'/>";

see live demo hererefer article How to refresh DIV using jquery

在此处查看现场演示,请参阅文章如何使用 jquery 刷新 DIV

回答by Darin Dimitrov

This will depend on where you want to get the HTML fragment from. For example if it is a server side script that returns it you could use the .load()method to send an AJAX request to it and replace the contents of the div with it without navigating away from the page:

这将取决于您希望从何处获取 HTML 片段。例如,如果它是一个返回它的服务器端脚本,您可以使用该.load()方法向它发送 AJAX 请求并用它替换 div 的内容,而无需离开页面:

$('#divId').load('/myscript');