Skip to content

Instantly share code, notes, and snippets.

@rafaelrozon
Created August 10, 2015 14:00
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 rafaelrozon/c3ea2c62542aa9cb5a46 to your computer and use it in GitHub Desktop.
Save rafaelrozon/c3ea2c62542aa9cb5a46 to your computer and use it in GitHub Desktop.
function getAllData(targetUrl) {
$.ajax({
url: targetUrl,
type: 'GET',
dataType: 'json',
success: function (data) {
// process data
},
error: function () {
// process error
}
});
}
function AddData(targetUrl) {
//create an object
var myObject = {
propertyOne: $('#someID').val(),
propertyTwo: $('#anotherID').val(),
};
$.ajax({
url: targetUrl,
type: 'POST',
data: JSON.stringify(myObject), // make a json object out of the js object
contentType: "application/json;charset=utf-8",
success: function (data) {
// process data
},
error: function () {
// process error
}
});
}
function DeleteData(target) {
// get the id of the data to delete
var id = $('#dataId').val()
$.ajax({
url: target + id,
type: 'DELETE',
contentType: "application/json;charset=utf-8",
success: function (data) {
// process data
},
error: function () {
// process error
}
});
}
function GetData(target) {
// get the id of the data to retrieve
var id = $('#dataId').val();
$.ajax({
url: target + id, // pass the id with the url
type: 'GET',
dataType: 'json',
success: function (data) {
// process data
},
error: function () {
// process error
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment