06-16-2016, 10:04 PM
create one file called ajax.js and put the following
<pre></pre>
after create the file Update.js and put the following
<pre></pre>
I hope this little Ajax engine is integrated with UserSpace and subsequently continue improving
<pre>
Code:
Ajax={};
Ajax.buildRequest = function(metodo, url, callback)
{
this.request = (window.XMLHttpRequest)? new XMLHttpRequest(): new ActiveXObject("MSXML2.XMLHTTP");
this.request.onreadystatechange = callback;
this.request.open(metodo, url, true);
this.request.send(url);
}
Ajax.checkState = function(_id)
{
switch(this.request.readyState)
{
case 0:
// se aƱade logica para actualizar algun componente visual por ejemplo
document.getElementById(_id).innerHTML = 'Sin inicializar ...';
break;
case 1:
document.getElementById(_id).innerHTML = 'Cargando ...';
break;
case 2:
document.getElementById(_id).innerHTML = 'Cargado...';
break;
case 3:
document.getElementById(_id).innerHTML = 'Interactivo...';
break;
case 4:
document.getElementById(_id).innerHTML = 'Listo';
return this.request.status;
}
}
Ajax.getResponse = function()
{
if(this.request.getResponseHeader('Content-Type').indexOf('xml') != -1)
{
return this.request.responseXML.documentElement;
}
else
{
return this.request.responseText;
}
}
after create the file Update.js and put the following
<pre>
Code:
Updater = {};
Updater.initialize = function()
{
Updater.isWorking = false;
}
Updater.initialize();
Updater.process = function(method , service, callback)
{
if(callback == undefined || callback == "") { callback = Updater.onResponse; }
Ajax.buildRequest(method, service, callback);
Updater.isWorking = true;
}
Updater.onResponse = function()
{
// Hacemos algo con la peticion ( feel free) ponga aqui su codigo
if(Ajax.checkState('loading') == 200)
{
Updater.isWorking = false;
}
}
I hope this little Ajax engine is integrated with UserSpace and subsequently continue improving