一个ajax脚本来检查一个文件,如果有什么变化,请刷新另一个文件! [英] one ajax script to check one file ,and if something change do refresh the other file!

查看:45
本文介绍了一个ajax脚本来检查一个文件,如果有什么变化,请刷新另一个文件!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个想法,我想知道它是否可能!


i得到一个带有ajax脚本的php文件,调用其他php文件以div显示它,文件大小是7 KB,在这个文件中有一个代码可以计算显示帖子的帖子和代码!


我想的是而不是刷新每4秒7 KB的文件,我想制作一个计数器的小文件,它可以是700字节,如果有一些东西改变它将执行7 KB文件并显示新帖子,所以如果我能做到这一点,我保存90%的带宽到服务器!!!


可以帮助我吗?


thanx !!!

I got an idea and i want to know if its possible!

i got a php file with ajax script that calling other php file to display it in a div ,the file size is 7 KB ,in this file there is a code that count posts and code that display the posts !

what i was thinking is instead of refreshing the file that is 7 KB every 4 second ,i want to make a little file of the counter ,that it can be 700 bytes ,and if some thing as changed it will excute the 7 KB file and display the new posts ,so if i can do that ,im saveing 90 precent of band width to the server!!!

can some help me do that?

thanx!!!

推荐答案

嗨...为什么不:) ...你的回调处理响应只需要处理它...你可以请求php文件 - 如果有什么改变它的行为就像它是,如果它没有改变,只返回一个假或任何... ...你的回调处理它,不需要触发什么都有...


亲切的问候
hi ... why not :) ... your callback that handles the response just need to handle it ... you could request the php-file - if something has changed it behaves as it is and in case it is unchanged just return a false or whatever ... and your callback handles it and don''t need to process anything ...

kind regards


我在哪里可以找到类似的东西?


我不是专家:)


我怎么能用ifs


就像在file.php中有些东西改变一样,然后继续并刷新file1.php,如果没有,什么都不做!!


thanx !! :)
where can i find exemple for something like that?

im not expert :)

how can i use it with ifs

like if some thing change in file.php ,then continue and refresh file1.php ,if not ,do nothing!!

thanx!! :)


我想我不明白这个问题。典型的流程是(简化的):


1.启动XMLHttpRequest

2.服务器端服务处理一些东西

3。服务器发送响应

4. XMLHttpRequest-Object的回调函数处理响应


所以你只需要调整从服务器发送的响应反映事情是否发生了变化。我猜php文件询问数据库或其他什么,所以它应该很容易''回声''或者什么''正常''响应或者假如没有改变?所以回调,分配给你的onreadystatechange属性的函数,只需要处理它收到的响应吗?


没有看到你有什么,并进一步解释你的代码已经建议的事情是猜测吗?


亲切的问候
i think i don''t understand the problem. the typical flow is (simplified):

1. start a XMLHttpRequest
2. the serverside service processes something
3. server sends response
4. XMLHttpRequest-Object''s callback function processes the response

so you just need to adapt the response that is send from the server to reflect whether something has changed or not. i guess the php-file asks a database or whatever and so it should be easy to ''echo'' or whatever the ''normal'' response or a false in case nothing was changed? and so the callback, the function that is assigned to your onreadystatechange property, just need to handle the response that it receives?

without seeing what you have and a further explaination what your code already does it would be guesswork to advice something ...

kind regards


这篇关于一个ajax脚本来检查一个文件,如果有什么变化,请刷新另一个文件!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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