-4
매 5 초마다 새로 고침을 시도하지만 작동하지 않습니다. 파일이 3 개 있습니다. 포함DIV 자동 새로 고침
의 index.php :
<html>
<head>
<script type="text/javascript" src="javascript/jquery-1.3.2.js" ></script>
<script type="text/javascript" src="javascript/javascript.js" ></script>
<script type="text/javascript">
$(document).ready(function(){
setInterval ("newmsg()", 5000);
setInterval ("newpause()", 5000);
});
</script>
</head>
<body>
<div id="msgs">
<?php echo date("H:i:s"); ?>
</div>
</body>
</html>
가 그럼 난 javascript.js이
<?php
echo 'ivan';
?>
수있는 사람을하시기 바랍니다 포함
function GetXmlHttpObject() {
var xmlHttp = null;
try {
xmlHttp = new XMLHttpRequest();
}
catch (e) {
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
function newmsg(){
var request = GetXmlHttpObject();
request.open("get", "msgsprint.php", true);
request.send(null);
request.onreadystatechange = function response() {
if (request.readyState === 4) {
if(request.responseText != "false"){
$('#msgs').html(request.responseText);
}
}
}
}
function newpause(){
var request = GetXmlHttpObject();
request.open("get", "newpauseprint.php", true);
request.send(null);
request.onreadystatechange = function response() {
if (request.readyState === 4) {
if(request.responseText != "false"){
$('#newpauselist').html(request.responseText);
}
}
}
}
그리고 난이 msgsprint.php을 포함 내가 뭘 잘못했는지 말해줘.
작동하지 않는 기능은 무엇입니까? 너 뭐 해봤 니? 오류 메시지가 나타 납니까? –
Ajax 호출을 사용할 때는'setInterval'을 사용하지 말아야합니다. Ajax 요청에 5 초 이상 걸리면 전화가 쌓이기 시작합니다. 대신'setTimeout'을 사용하고, Ajax 호출이 완료되면 5 초의 새로운 타임 아웃을 설정하십시오. 그렇게하면 당신은 그들이 쌓이지 않을 것이라고 확신 할 수 있습니다. –
thx, 오류 없음, div 만 새로 고치지 않습니다. – zonelsk