× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ajax Engine for UserSpice V0.1
#1
create one file called ajax.js and put the following

<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;
}
}
</pre>


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;
    }
}
</pre>


I hope this little Ajax engine is integrated with UserSpace and subsequently continue improving

  Reply
#2
What do you think ?
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)