Created
July 27, 2016 17:36
-
-
Save UlisesGascon/d6ff22c8325c058bd72119dc84855d0b to your computer and use it in GitHub Desktop.
Simple Ajax Management
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
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