2011-08-24 7 views
1

php 및 jQueryMobile의 코드 작성. 내가 사업부를 얻기 위해 노력하고새로 고침 시간이 변경되면 jQuery Mobile에서 div를 동적으로 새로 고치려면 어떻게해야합니까?

은 그래서이 코드는 한 번 발사 및 대해 refreshTime이 경과 한 후 사업부를 dynamicContent에 새로 고쳐집니다 변수 대해 refreshTime

<div id="dynamicContent"> 
<em><?= $this->subtitle ?></em> 
<img src="<?= $this->image ?>"/> 
<em><?= $this->synopsis ?></em> 
<br/> set refresh: <?= $this->refreshTime?> time on server: <?= date("H:i",time());?> 
<h2><a href="<?=$this->irrelaventLink ?>"> More Details</a></h2> 
</div> 

<script> 
setTimeout(function() { 
       $('#dynamicContent').load('/url/that/generates/plain/html/'); 
      },<?= $this->refreshTime ?>*1000); 
</script> 

에 따라 새로 고칩니다. 문제가 생기면 새로 고치기 위해 refreshTime 값을 새로 고치기를 원합니다.

jQuery 방식이 작동하는 경우 모바일을 사용하여 그 모습을 볼 수는 있지만 기꺼이 웹을 검색하여 jQuery 모바일 방식을 찾고 있습니다.

<br/> set refresh: <?= $this->refreshTime?> time on server: <?= date("H:i",time());?> 

평가

모든 의견/생각/답변을 디버깅에만 있는가 : 라인이

참고.

건배

답변

3

당신은 하드의 setTimeout 기능으로 새로 고침 시간을 코딩했습니다. 동적 인 것처럼 보이지만, 페이지가 생성되고 PHP가 값을 채울 때 값이 설정되기 때문에. 그 후 HTML로 하드 코드되고 변경되지 않습니다.

var refreshTime = <?= $this->refreshTime ?>; // set initial value 

function refreshContent() { 
    $.ajax({ 
     url: '/url/that/generates/no/longer/plain/html', 
     dataType: 'json', 
     success: function(data) { 
      refreshTime = data.refreshTime; 
      $('#dynamicContent').html(data.content); 
      setTimeout(refreshContent, refreshTime); 
     } 
    }); 
} 
refreshContent(); 

그런 다음 수정해야 다음 대해 refreshTime이 일 e 서버에 무슨 일이 일어나고 무엇에 의존하는 경우

, 당신은 동적으로 생성 된 콘텐츠와 함께 그 새로운 시간 간격을 반환하도록 서버를 얻을 수있는 것 스크립트는 URL을 생성하여 새로운 내용과 새 새로 고침 시간이 포함 된 json 데이터 구조를 반환합니다.

관련 문제