dougou6727 2014-04-27 15:28
浏览 61

使用jQuery自动重新加载页面

I have a test page that I keep all my labs on on my local IDE (MAMP). I recently wrote a small php script that will read the directory and create a link of each file in that directory which is help to me as now i don't have to write out the full local url each time to test a new file. I still have to refresh the page though every time i create a new file so its' read. I wanted to set the page to being 'self-reading' so that when i add something, it would appear on the page. I thought Ajax would be a good use of this but the script i tried doesn't work. I've no knowledge of ajax and or jQuery - i'm a super newb honestly - but i'm trying to grow.

My problem in a nut shell: The script does not appear to update the page (maybe it is and i'm not doing it right? I don't know - maybe i ought to be using javascript to refresh the page?)

my code:

<!-- For ease of use, use JQuery hosted lib- you can download any version and link to it locally also -->
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
 $(document).ready(function() {
 $("#responsecontainer").load("response.php");
   var refreshId = setInterval(function() {
      $("#responsecontainer").load('response.php?randval='+ Math.random());
   }, 1000);
   $.ajaxSetup({ cache: false });
});
</script>

<div id="responsecontainer">

<?php //index.php
$dir_open = opendir('.');

while(false !== ($filename = readdir($dir_open))){

    if($filename != "." && $filename != ".."){
        $link = "<a href='./$filename' target='_blank'> $filename </a><br />";
        echo $link;
    }
}
closedir($dir_open);
?>

</div>
<!-- End jQuery auto update div -->
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程
    • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
    • ¥15 关于smbclient 库的使用
    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启