Scripts | Codes

All languages in three languages :-)
Showing posts with label ajax. Show all posts

Une requête AJAX qui marche sur tout les navigateurs avec toutes les versions...

An AJAX request that works on all browsers with all versions

تطبيق أجاكس التي تعمل على جميع المتصفحات مع جميع الإصدارات..


Open in a new window
//###################################################
// find more codes on scripts-n-codes.blogspot.com
//###################################################
//
//  this files -> ajax.js (to include on pages that uses ajax requests)
//
function get_url(url) {
 var request = false;  
 if(window.XMLHttpRequest) {  
  request = new XMLHttpRequest();  
  if(request.overrideMimeType) {  
   request.overrideMimeType('text/xml');  
  }  
 } else if(window.ActiveXObject) {  
  var versions = ['Microsoft.XMLHTTP', 'MSXML.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.7.0', 'Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP'];  
  for(var i=0; i<versions.length; i++) {  
   try {  
    request = new ActiveXObject(versions[i]);  
   } catch(e) {}  
  }  
 }  
 xmlHttpReq = request;  
 xmlHttpReq.open("GET",url, false);
 xmlHttpReq.send(null);
 return xmlHttpReq.responseText; 
}





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>
Subscribe to: Posts (Atom)
attendez....