Created
March 5, 2018 18:01
-
-
Save ZeusAFK/07f504b608b630d13951a82e98efb04c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.__debug = true; | |
window.__webroot = 'http://localhost/web/'; | |
// Este es simplemente un wrapper para JQuery.Ajax | |
function doAjaxRequest(url, type, data, callback, failback){ | |
window.__debug && console.log('loading module data', url); | |
var request = $.ajax({ | |
type: type, | |
url: window.__webroot + url, | |
data: { data : data }, | |
dataType: 'json', | |
cache: false, | |
success: function(response){ | |
window.__debug && console.log(url, response); | |
callback && callback(response); | |
} | |
}); | |
request.fail(function(jqXHR, textStatus){ | |
window.__debug && console.log(url, jqXHR); | |
failback && failback(url, jqXHR); | |
}); | |
} | |
var data = { 'a' : 1, 'b' : 2, 'c' : 3}; | |
// Parametros: URL, TIPO [GET, POST], DATOS, CALLBACK SUCCESS, CALLBACK FAIL | |
doAjaxRequest('info-something/12345', 'post', data, function(response){ | |
// Cualquier otro indicador que tengas para confirmar el exito de la solicitud | |
if(response.result == 1){ | |
console.log('request success'); | |
}else{ | |
console.log('request failed'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment