Advertisement
venuv

Create new Parse.com object using REST API and POST

Aug 25th, 2015
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!-- in summary, 3 things:
  2.  0. set the request headers, application/json may or may not be needed
  3.  1. make sure you enter the REST-API-KEY not the Javascript key
  4.  2. 'quote' the JSON structure, else you get an invalid JSON, 400 message
  5. -->
  6.     var serverUrl = 'https://api.parse.com/1/classes/Test';
  7.     alert("before ajax");
  8.     $.ajax({
  9.       type: "POST",
  10.       url: serverUrl,
  11.       beforeSend: function(request) {
  12.       request.setRequestHeader("X-Parse-Application-Id", 'MY-APP-ID');
  13.       request.setRequestHeader("X-Parse-REST-API-Key", 'MY-REST-API-KEY');
  14.       request.setRequestHeader("Content-Type","application/json");
  15.     },
  16.     data: '{"Sport":"Cricket","Comment":"super popular"}',
  17.     success: function(msg){
  18.        alert('yay' + JSON.stringify(msg));
  19.     },
  20.     error: function(msg){
  21.        alert('boo' + JSON.stringify(msg));
  22.     }
  23.     });
  24.     alert("executed parsePost");
  25.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement