Un exemple de comment utiliser AJAX pour rafraichir une page sans l'actualiser...
Sans commentaires
An example of how to use AJAX to refresh a page without updating it ...
No comments
مثال عن كيفية إستعمال أجاكس لتحديث جزء من صفحة دون تحديثها كليا
بدون تعليق
Open in a new window
//##################################################
// find more codes on codes-n-scripts.blogspot.com
//##################################################
//
// this is ajax.js file
//
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
ro = new XMLHttpRequest();
}
return ro;
}
var http = createRequestObject();
function sndReq(action) {
http.open('get', 'ajax.php?action='+action);
http.onreadystatechange = handleResponse;
http.send(null);
}
function handleResponse() {
if(http.readyState == 4){
var response = http.responseText;
var update = new Array();
if(response.indexOf('|' != -1)) {
update = response.split('|');
document.getElementById(update[0]).innerHTML = update[1];
}
}
}<?
//##################################################
// find more codes on codes-n-scripts.blogspot.com
//##################################################
//
// this is ajax.php file
//
switch($_REQUEST['action']) {
case 'A1':
echo "A1|Je suis dans la case bleue";
break;
case 'B1':
echo "B1|je suis dans la case verte";
break;
}
?><html><body>
<script src="ajax.js"></script>
<!-- find more codes on codes-n-scripts.blogspot.com -->
<!-- this is index.html -->
<TABLE BORDER="0">
<TR>
<TD id="A1" HEIGHT="200" WIDTH="197" BGCOLOR="blue" ALIGN="center">
</TD>
</TR>
<TR>
<TD id="B1" BGCOLOR="green" ALIGN="center">
</TD>
<TD HEIGHT="350" WIDTH="750" BGCOLOR="red" id="B2" ALIGN="center">
<a href="javascript:sndReq('A1')">Afficher un text dans la case bleue</a><BR>
<a href="javascript:sndReq('B1')">Afficher un text dans la case verte</a>
</TD>
</TR>
</TABLE>
</body></html>