Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function() {
- var data;
- var url = 'https://www.parse.com/1/classes';
- var headers = {
- 'X-Parse-REST-API-Key': 'sukxawLKr4aGfm71iZRuzDQbqIx4idO1FmOXp0l6',
- 'X-Parse-Application-Id' : 'HgGJ0tt0Pa1oEpxLUw4nGJYYzvoPOlQZNzPruOzN'
- }
- function POST(extraUrl, data) {
- $.ajax({
- method: 'POST',
- headers: headers,
- data: JSON.stringify(data),
- url: url + extraUrl
- }).success(function () {
- console.log('item added');
- });
- }
- function PUT(extraUrl, id) {
- var name = prompt('Name of country:');
- data = {
- name: name
- }
- $.ajax({
- method: 'PUT',
- headers: headers,
- data: JSON.stringify(data),
- url: url + extraUrl + '/' + id
- }).success(function (data) {
- console.log('item updated');
- });
- }
- function GET(extraUrl) {
- $.ajax({
- method: 'GET',
- headers: headers,
- async: false,
- url: url + extraUrl
- }).success(function (result) {
- data = result;
- });
- }
- function DELETE(extraUrl, id) {
- $.ajax({
- method: 'DELETE',
- headers: headers,
- url: url + extraUrl + '/' + id
- }).success(function () {
- console.log('item deleted');
- });
- }
- function showCountries() {
- var extraUrl = '/Country';
- GET(extraUrl);
- var ol = $('<ol>');
- for (var i = 0; i < data.results.length; i++) {
- var countryName = data.results[i].name;
- var id = data.results[i].objectId;
- var li = $('<li>').text(countryName);
- var btnDelete = $('<button>').text('DELETE').click(function () {
- DELETE(extraUrl, '/' + id);
- });
- var btnEdit = $('<button>').text('EDIT').click(function () {
- PUT(extraUrl, '/' + id);
- });
- btnDelete.appendTo(li);
- btnEdit.appendTo(li);
- li.appendTo(ol);
- }
- $('#wrapper').append(ol);
- }
- showCountries();
- }())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement