View Single Post
ישן 26-10-10, 17:45   # 1
Skfir
חסום
 
מיני פרופיל
תאריך הצטרפות: May 2009
מיקום: הוד השרון
גיל: 33
הודעות: 552
שלח הודעה באמצעות ICO אל Skfir שלח הודעה באמצעות MSN אל Skfir

Skfir לא מחובר  

בעיה פשוטה ברענון ב 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 עד שאני לא מרענן את הדף
  Reply With Quote