Código Javascript:
Ver original
Request = function(){ var Request = window.XMLHttpRequest?new XMLHttpRequest():window.ActiveXObject?new ActiveXObject("Microsoft.XMLHTTP"):false; Request.fn = function(fn){ if(typeof fn=='string')return new Function(fn); if(typeof fn=='function')return fn; if(typeof fn=='undefined')return new Function(); }; Request.config = { 'xml' : false, '404' : 'File not found' }; Request.success = false; Request.loading = false; Request.error = false; Request.submit = function(obj){ if(Request){ Request.open("POST", obj.url, true); Request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8;'); //esto es para el error 406 de los servidores Request.send(null); Request.onreadystatechange = function(){ if(Request.readyState==4){ if((Request.status==200)||(Request.status==0)){ Response = Request.config['xml']?Request.responseXml:Request.responseText; if(Request.success){ Request.fn(Request.success).call(this, Response, Request); } else { Request.fn(obj.success).call(this, Response, Request); } } else { if(Request.success){ Request.fn(Request.loading).call(this, Request); } else { Request.fn(obj.loading).call(this, Request); } } } else { if(Request.success){ Request.fn(Request.error).call(this, Request.config['404']); } else { Request.fn(obj.error).call(this, Request.config['404']); } }; } } else obj.error.call(this, Request); }; return Request; };
y lo utilizo de la siguiente forma
Código Javascript:
Ver original
var req = new Request; req.submit({ url : 'plik.xml', xml : false, success : function(res, req){ document.getElementById('p2').innerHTML = res; }, loading : function(){ console.log('loading...'); }, error : function(err){ console.log(err); } });
EL problema es que no logro que las funciones de loading y de error hagan algo es decir no me ejecutan nada ni alert ni nada por el estilo
Muchas gracias por su tiempo y espero que me puedan ayudar