Last active
March 27, 2019 18:47
-
-
Save bellydrum/4e4548befe614d8b293901ade2126fc6 to your computer and use it in GitHub Desktop.
Ajax Wrapper
This file contains 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
/** | |
* ajaxHelper.js | |
* written by bellydrum to make ajax even easier | |
* ------------------------------------------------------------------------------ | |
* @param url (string) - url from which to request data | |
* @param requestType (string) - type of request | |
* @param data (optional: object) - data required to make request | |
* @returns | |
* - success: {Promise<*>} | |
* - failure: error | |
* - there was an error making the ajax call to the given url | |
* | |
* @about - standardized wrapper for ajax calls | |
*/ | |
async function ajaxCall(url, requestType, data=null) { | |
try { | |
let result = await $.ajax({ | |
url: url, | |
type: requestType, | |
data: data, | |
success: result => { return result }, | |
error: error => { return error } | |
}) | |
return result | |
} catch(error) { | |
throw error | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment