Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- JSPlus.ajax = function(obj){
- var xhr = (function(){
- var xhr = false;
- if (window.XMLHttpRequest) { // Chrome, FF, Safari,...
- (xhr = new XMLHttpRequest()).overrideMimeType && xhr.overrideMimeType('text/xml');
- } else if (window.ActiveXObject) { // IE
- try {
- xhr = new ActiveXObject("Msxml2.XMLHTTP");
- } catch (e) {
- try {
- xhr = new ActiveXObject("Microsoft.XMLHTTP");
- } catch (e) {
- console.log('Tu navegador es muy antiguo, no soporta AJAX');
- throw e;
- }
- }
- }
- return xhr;
- })();
- JSPlus.calcar(obj, JSPlus.ajax.porDefecto);
- xhr.open(obj.metodo, obj.url, obj.async);
- for(var i in obj.headers){
- obj.headers.hasOwnProperty(i) && xhr.setRequestHeader(i, obj.headers[i]);
- }
- xhr.onreadystatechange = function(){
- console.log(obj);
- xhr.readyState == 4 && xhr.status == 200 && obj.ok(xhr.responseText);
- };
- xhr.send(obj.info);
- };
- JSPlus.ajax.porDefecto = {
- 'url' : 'index.php',
- 'metodo' : 'GET',
- 'info' : '',
- 'ok' : function(){},
- 'async' : true,
- 'headers' : {},
- 'contexto' : null
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement