Last active
December 15, 2015 04:58
-
-
Save Marthyn/5205028 to your computer and use it in GitHub Desktop.
Jquery Ajax Requests
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
var api = "yourApiUrlGoesHere"; | |
/* | |
Method to do a GET request to the service | |
*/ | |
var getService = function (uri, failureFunction, errorFunction, successFunction) | |
{ | |
$.ajax({ | |
cache: true, | |
url: api+uri, | |
type: "GET", | |
contentType: "application/javascript", | |
dataType: "json", | |
crossDomain: true, | |
error: errorFunction, | |
failure: failureFunction, | |
success: successFunction | |
}); | |
}; | |
/* | |
Method to do a POST request to the service | |
*/ | |
var postService = function (uri, data, failureFunction, errorFunction, successFunction) | |
{ | |
$.ajax({ | |
type: 'POST', | |
url: capp_api+uri, | |
contentType : "application/json; charset=utf-8", | |
data: JSON.stringify( data ), | |
dataType: "json", | |
crossDomain: true, | |
error: errorFunction, | |
failure: failureFunction, | |
success: successFunction | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment