Created
August 10, 2015 14:00
-
-
Save rafaelrozon/c3ea2c62542aa9cb5a46 to your computer and use it in GitHub Desktop.
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
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