任何幫助在這裏都是值得讚賞的。我正在php中構建一個web應用程序,並且使用了有很多內置工具的Yii MVC框架。正如標題所說,我需要每隔10秒刷新一次div。目前,我有這個AJAX功能如何使用jquery或ajax以10秒爲間隔刷新div
<script type="text/javascript">
function ajaxFunction(){
var ajaxRequest;
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
var list = document.getElementById('logged_in_users_list');
if(ajaxRequest.readyState == 4){
list.innerHTML = ajaxRequest.responseText;
setTimeout('ajaxFunction()',10000);
}
}
ajaxRequest.open("GET", "protected/controllers/room/openRoom", true);
ajaxRequest.send(null);
}
</script>
<script type="text/javascript">
setInterval(function() {ajaxFunction();}, 5000);
</script>
對於那些你們誰不熟悉的Yii它存儲大多數你的PHP文件名爲保護的文件夾中。那麼它就是這樣,上面的代碼的ajaxRequest.open行請求該URL存儲在受保護的文件夾內,所以我一直得到訪問禁止403錯誤。任何想法如何我可以實現與jQuery不同的東西或繞過此訪問問題?