Skip to content

Instantly share code, notes, and snippets.

@Marthyn
Last active December 15, 2015 04:58
Show Gist options
  • Save Marthyn/5205028 to your computer and use it in GitHub Desktop.
Save Marthyn/5205028 to your computer and use it in GitHub Desktop.
Jquery Ajax Requests
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