나는 약간의 MySQL 콘텐츠가있는 <div id="refresh">
이 있습니다. 당신이 눈치 경우자동 새로 고침 채팅 문제
0 seconds
+-------------------------------------+
|Randome Text |
|This is such a cool chat room |
|Not really |
+-------------------------------------+
3 seconds
+-------------------------------------+
|Randome Text |
|This is such a cool chat room |
|Not really |
|This is such a cool chat room |
|Not really |
+-------------------------------------+
은, 그것은 게시물을 남겼습니다 그것과 같을 것이다 그래서 실제로 코드의 중복을 처음 게시
<script type="text/javascript">
var auto_refreshs_contents = setInterval(
function(){
$('#refresh').load('index.php?_=' +Math.random()+' #refresh').fadeIn("slow"); // load div.refresh
}
, 3000); // refresh every 3 seconds
</script>
: 나는이 자바 스크립트 코드가 "무작위 텍스트". 나는 이유를 모른다. 하지만 처음에는 기본적으로 그렇게합니다. 그런 다음 6 초 후에 새로 고침을하지만 내용이 더 이상 나타나지 않으면 오른쪽에서 새로 고칩니다. 따라서 페이지를 새로 고치기 전에 페이지의 내용을 지우기로 결정했습니다.
<script type="text/javascript">
var auto_clearContents = setInterval(
function(){
$("#refresh").html(""); //clear contents of div#refresh
}
, 3000); //clear existing contents every 3 seconds
var auto_refreshs_contents = setInterval(
function(){
$('#refresh').load('index.php?_=' +Math.random()+' #refresh').fadeIn("slow"); // load div.refresh
}
, 3000); // refresh every 3 seconds
</script>
하지만 이상한 일이 생길 때가 있습니다. Chrome Developers Tools의 networks
탭을보고 있는데 200ms마다 (200 번) 새로 고침하고 때로는 2.5 초가 걸리는 것으로 나타났습니다. 나는 모른다 ...
내 코드에 문제가 있습니까? 그것을 할 수있는 더 좋은 방법이 있습니까? 감사!
다음은 각 load() 사이의 밀리 초 수를 실제로 보여주는 또 다른 버전입니다. http://jsfiddle.net/Gm82w/7/ – davehale23
div를 ID로 참조해야합니까? 또는 다음과 같이 클래스를 가질 수 있습니다 : –
$ ('refresh') .load ('inc/chat.php.messages'). fadeIn ("slow "); 내가 물어 보는 이유는 여러 번 사용되기 때문에 DIVS를 클래스로 변경했기 때문입니다. 그리고 지금은 상쾌하지 않습니다. –