任何帮助在这里都是值得赞赏的。我正在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不同的东西或绕过此访问问题?