82 lines
2.4 KiB
JavaScript
Executable File
82 lines
2.4 KiB
JavaScript
Executable File
/********************************************/
|
|
/* ajax.js By BELLOUNDJA Abdelkader */
|
|
/* Dader51@hotmail.com */
|
|
/********************************************/
|
|
|
|
var xmlhttp = null;
|
|
|
|
function senddata(server, data, callback) {
|
|
if (!xmlhttp) xmlhttp = new XMLHttpRequest();
|
|
//document.getElementById('load').style.display = 'block';
|
|
xmlhttp.onreadystatechange = function() {
|
|
xhrMonitor(xmlhttp.readyState);
|
|
if (xmlhttp.readyState == 4){
|
|
if (xmlhttp.status == 200 || 1) {
|
|
if (callback) callback(xmlhttp.responseText);
|
|
xhrMonitor(0);
|
|
} else {
|
|
alert('Erreur http : ' + xmlhttp.status);
|
|
}
|
|
//document.getElementById('load').style.display = 'none';
|
|
}
|
|
}
|
|
xmlhttp.open("POST", server, true);
|
|
xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
|
|
xmlhttp.send(data);
|
|
|
|
}
|
|
|
|
function sendDATA(server, data, callback) {
|
|
if (!xmlhttp) xmlhttp = new XMLHttpRequest();
|
|
//document.getElementById('load').style.display = 'block';
|
|
xmlhttp.onreadystatechange = function() {
|
|
xhrMonitor(xmlhttp.readyState);
|
|
if (xmlhttp.readyState == 4){
|
|
if (xmlhttp.status == 200) {
|
|
if (callback) callback(xmlhttp);
|
|
xhrMonitor(xmlhttp.readyState);
|
|
} else {
|
|
alert('Erreur http : ' + xmlhttp.status);
|
|
}
|
|
//document.getElementById('load').style.display = 'none';
|
|
}
|
|
}
|
|
xmlhttp.open("POST", server, true);
|
|
xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
|
|
xmlhttp.send(data);
|
|
}
|
|
|
|
function xhrMonitor(rS) {
|
|
|
|
if (rS == 0) rS = 'zero';
|
|
if (rS == 1) rS = 'one';
|
|
if (rS == 2) rS = 'two';
|
|
if (rS == 3) rS = 'three';
|
|
if (rS == 4) rS = 'four';
|
|
document.getElementById('xhrMonitor').className = rS;
|
|
|
|
}
|
|
|
|
function makeXhrMon(elem) {
|
|
|
|
function xhrtoggle(e) {
|
|
|
|
e.stopPropagation();
|
|
if (document.getElementById('xhrMonitor').hasClassName('active')) return document.getElementById('xhrMonitor').removeClassName('active');
|
|
return document.getElementById('xhrMonitor').addClassName('active');
|
|
}
|
|
|
|
function xhrfree() {
|
|
document.getElementById('xhrMonitor').removeClassName('active');
|
|
}
|
|
|
|
var sp = document.getElementById('xhrMonitor').getElementsByTagName('span');
|
|
for (var i = 0; i < 5; i++) {
|
|
|
|
eval("sp[i + 1].addEventListener('click', function () {if ( document.getElementById('xhrMonitor').hasClassName('active') ) xhrMonitor(" + i + ");}, false); ");
|
|
}
|
|
|
|
elem.addEventListener('click', xhrtoggle, false);
|
|
document.addEventListener('click', xhrfree, false);
|
|
|
|
} |