Skip to content

Instantly share code, notes, and snippets.

@UlisesGascon
Created July 27, 2016 17:36
Show Gist options
  • Save UlisesGascon/d6ff22c8325c058bd72119dc84855d0b to your computer and use it in GitHub Desktop.
Save UlisesGascon/d6ff22c8325c058bd72119dc84855d0b to your computer and use it in GitHub Desktop.
Simple Ajax Management
function updateHTML (datosdb){
console.log("Data from Ajax request: ", datosdb);
/*
-- UPDATE HTML --
*/
}
function errorDatos (err){
console.warn("Error in Ajax Request: ", err);
/*
-- UPDATE HTML (if needed)
*/
}
// Simple (GET only)
function ajaxManagement (url, successCallback, failureCallback){
if(url && successCallback){
var request = $.ajax({
url: url,
method: "GET",
dataType: "json"
});
request.done(function( data ) {
successCallback(data);
});
if(failureCallback){
failureCallback(textStatus);
} else {
console.info("IMPORTANT: No FAILURECALLBACK Provided... It is optional, but highly recommended")
}
} else {
console.warn("ERROR: Missing URL or SUCCESSCALLBACK!")
}
}
// Demo
ajaxManagement("/database/consulta.php", updateHTML, errorDatos);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment