הוסטס - פורום אחסון האתרים הגדול בישראל

הוסטס - פורום אחסון האתרים הגדול בישראל (https://hosts.co.il/forums/index.php)
-   פורום תיכנות (https://hosts.co.il/forums/forumdisplay.php?f=14)
-   -   בעיה פשוטה ברענון ב ajax (https://hosts.co.il/forums/showthread.php?t=85918)

Skfir 26-10-10 17:45

בעיה פשוטה ברענון ב ajax
 
ajax.js
קוד:

function createRequestObject() {
        var ro;
        if (window.XMLHttpRequest){
                try {
                        ro = new XMLHttpRequest();
                } catch(e) {
                        ro = false;
                }
        } else if(window.ActiveXObject){
                try{
                        ro = new ActiveXObject("Msxml2.HTMLHTTP");
                } catch(e) {
                        try{
                                ro=new ActiveXObject("Microsoft.XMLHTTP");
                        } catch(e) {
                                ro = false;
                        }
                }
        }
        return ro;
}

var http = createRequestObject();
function ajax(url,target) {
        http.open('GET', url,true);
        http.onreadystatechange = handleResponse(target);
        http.send(null);
}
function handleResponse(target) {
        if(http.readyState == 4){
                var response = http.responseText;
                document.getElementById(target).innerHTML=response
        }
}

window.onload=function(){
        setTimeout("ajax('index.php','output')",1000);
}

index.html

קוד:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <script language="JavaScript" src="ajax.js" type="text/javascript"></script>
  <title>Hello!</title>
</head>

<body>
<div id="output"></div>
</body>

</html>


index.php
קוד:

<?php
        header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
        header("Cache-Control: no-cache");
        header("Pragma: no-cache");
        echo "bla";
?>

סבבה זה מציג את התוכן של index.php ב div output אבל זה לא מרענן אותו... (setTimeOut)
למשל עכשיו כתוב bla ושיניתי ל bla1 זה לא מציג bla1 עד שאני לא מרענן את הדף

Hagaibl 31-10-10 20:22

במקום
setTimeout
נסה לעבוד עם
setInterval

IgalSt 31-10-10 22:48

בנוסף, נסה להוסיף מספר רנדומלי אחרי ה- index.php?123
בכל פניה על מנת לוודא שאין קאשינג

Hagaibl 01-11-10 19:06

PHP קוד:

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");     header("Cache-Control: no-cache");     header("Pragma: no-cache"); 

זה נוגד אחד את השני. הכנס את הבאים במקום הHEADERS.
PHP קוד:

header("Expires: -1");
header("Cache-Control: no-cache");
header("Pragma: no-cache"); 



כל הזמנים הם GMT +2. הזמן כעת הוא 06:58.

מופעל באמצעות VBulletin גרסה 3.8.6
כל הזכויות שמורות ©
כל הזכויות שמורות לסולל יבוא ורשתות (1997) בע"מ