Skip to content

Instantly share code, notes, and snippets.

@bellydrum
Last active March 27, 2019 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bellydrum/4e4548befe614d8b293901ade2126fc6 to your computer and use it in GitHub Desktop.
Save bellydrum/4e4548befe614d8b293901ade2126fc6 to your computer and use it in GitHub Desktop.
Ajax Wrapper
/**
* 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