使用jQuery每10秒刷新一次使用php数据的div [英] Refresh a div with php data every 10 seconds using jQuery

查看:104
本文介绍了使用jQuery每10秒刷新一次使用php数据的div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的HTML代码是:

 <!DOCTYPE html> 
< head>
< title>无标题文档< / title>

< script src =http://code.jquery.com/jquery-latest.js>< / script>

< script>
$(document).ready(function(){
setInterval(function(){
$(#latestData)。load(getLatestData.php #latestData);
},10000);
});

< / script>
< / head>

< body>
< div id =latestData>

< / div>
< / body>
< / html>

我正在使用的PHP代码(暂时,因为我知道这不会因相同data):

 <?php 

echotest;

?>

然而,它甚至没有在html页面显示test我错了?



非常感谢

解决方案

jQuery load 方法以不同的方式工作。尝试阅读它的文档



你不用不必指定目标元素ID两次,删除第二个,如下所示:

  $(#latestData)。负载( getLatestData.php); 


Am trying to refresh data stored in a div every 10 seconds using jQuery.

My HTML code is:

<!DOCTYPE html>
<head>
<title>Untitled Document</title>

<script src="http://code.jquery.com/jquery-latest.js"></script>

<script>
    $(document).ready(function(){
        setInterval(function() {
            $("#latestData").load("getLatestData.php #latestData");
        }, 10000);
    });

</script>
</head>

<body>
    <div id = "latestData">

    </div>
</body>
</html>

And the PHP code I am using (temporarily as I know this won't change due to the same "data"):

<?php

    echo "test";

?>

However, it isn't even showing "test" on the html page.. could anyone suggest where I have gone wrong?

Many thanks

解决方案

jQuery load method works in a different way. Try reading its documentation.

You don't have to specify destination element ID twice, remove the second one, like this:

$("#latestData").load("getLatestData.php");

这篇关于使用jQuery每10秒刷新一次使用php数据的div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆