Javascript – Debug application en Ajax
Une utilisation originale d’AJAX pour tracker un dysfonctionnement entre le client et votre applicatif.
- Le javascript code :
- L’appel dans l’HTML page:
<script Language="JavaScript">
var from_time = new Date();
from_time = from_time.getTime();
function benchmark_loading_time() {
var to_time = new Date();
to_time = to_time.getTime();
var msecs = (to_time - from_time);
//submit the result
var req = null;
try { req = new XMLHttpRequest(); } catch(e) {}
if (!req) try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {}
if (!req) try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
req.open("GET", '/benchmark_loading_time.php?msecs=' + msecs + '&url=' + location.href, false);
req.send(null);
}
</script>
<body onLoad="benchmark_loading_time()>
- Cote serveur, le script PHP benchmark_loading_time.php se chargera de jouer avec les paramètres msecs et url
Source : lien

