2017-12-27 5 views
0

에서 작동하지 않습니다. info.php 내용은 다음과 같이로드 :jQuery를 내가 <strong>AJAX</strong>을 통해 <strong>info.php</strong>를로드하는 <strong>의 index.php</strong> 페이지가 XMLHttpRequest 객체

<script> 
function loadDoc() { 
    var xhttp = new XMLHttpRequest(); 
    xhttp.onreadystatechange = function() { 
    if (this.readyState == 4 && this.status == 200) { 
     document.getElementById("data").innerHTML = this.responseText; 
    } 
    }; 
    xhttp.open("GET", "info.php", true); 
    xhttp.send(); 
} 

(function() { 
    loadDoc() 
})(); 
setInterval ("loadDoc()", 5000); 
</script> 

info.php 파일은이/다운에서 카운트 할 수있는 다음과 같은 코드가/특정 번호로. 내가 info.php를 방문 할 때

<div class="timer count-title count-number" data-from="2000" data-to="300" data-speed="1500"></div> 

<script src='includes/jquery-3.2.1.min.js'></script> 
<script src="includes/counter.js"></script> 

직접 카운터는 완벽하게 잘 작동합니다. 그러나 index.php을 방문하면 카운터가 표시되지 않습니다. 다른 jQuery 스크립트에서도 동일한 문제가 발생했습니다. index.php에 jQuery와 다른 스크립트가 포함되어 있어도 여전히 작동하지 않습니다. 업데이트를 계속하기 때문에 전화 번호를 AJAX 호출을 통해 전달하려고합니다.

간단한 해결책이 있습니까? 당신이 따를 때처럼 JQuery와에 의해 그것을 할 수

+0

이것은 아니다 ... 다음 스크립트 함수 문 검사와 함께이 문제를 자신의 문제를 생각한다 jQuery 스크립트. 그것은 바닐라예요 –

+0

당신이 제 질문을 오해 한 것 같아요. jQuery 나 vanilla JS가 AJAX 호출을 통해로드되는 경우 작동하지 않습니다. – derrtyones

답변

0

은 ...

function loadDoc(){ 
      console.log("call done"); 
      $("#data").load("info.php", function() { 
       console.log("Load done."); 
      }); 

     }; 
     $(function(){loadDoc();}); 
     setInterval (loadDoc, 5000); 

나는

function loadDoc() { 
    var xhttp = new XMLHttpRequest(); 
    xhttp.onreadystatechange = function() { 
    if (this.readyState == 4 && this.status == 200) { 
     document.getElementById("data").innerHTML = this.responseText; 
    } 
    }; 
    xhttp.open("GET", "info.php", true); 
    xhttp.send(); 
} 

$(function(){loadDoc();}); 
setInterval (loadDoc, 5000); 
관련 문제