Reputation: 2172
I am creating an object using Parse's API and am confused on how and where to use it in my Javascript code.
Parse API: https://www.parse.com/docs/rest#objects-creating
This is an example of how to create an object stated in Parse's API:
curl -X POST \
-H "X-Parse-Application-Id: bLAj1fl7B77TZYo1zv9vIAiUgC19RXgpzsFZeVgM" \
-H "X-Parse-REST-API-Key: PPrIdiqZXMHT1JwveI2AdhsAhGpx7WjXfvYTSYXh" \
-H "Content-Type: application/json" \
-d '{"score":1337,"playerName":"Sean Plott","cheatMode":false}' \
https://api.parse.com/1/classes/GameScore
I'm trying to use AJAX to send a POST request which appends some text to a list item.
My Javascript code:
button.click(function(){ // Submitting text from a textbox
$.ajax({
url : 'https://api.parse.com/1/classes/<className>', // What is className?
type: 'POST',
data: text.val(), // Text the user inputted in a textbox
error: function (data) {
console.log('error');
},
success: function (data) {
$('ul').append('<li>' + data + '</li>');
}
});
});
How and where would I use the curl request like the example in my code? Also, I do not know what Parse means by 'className' in the url key. If the ul's class name that I wanted the text to appear in was called "message" then would url key in my AJAX request be 'https://api.parse.com/1/classes/Messages'?
Any help is appreciated! Thanks
Upvotes: 1
Views: 1330
Reputation: 388316
You need to use something like
$.ajax({
url : 'https://api.parse.com/1/classes/TestObject',
type : 'POST',
contentType : 'application/json',
headers : {
'X-Parse-Application-Id' : 'bLAj1fl7B77TZYo1zv9vIAiUgC19RXgpzsFZeVgM',
'X-Parse-REST-API-Key' : 'PPrIdiqZXMHT1JwveI2AdhsAhGpx7WjXfvYTSYXh'
},
data : JSON.stringify({
key : 'value: ' + new Date().getTime()
}),
error : function(data) {
console.log('error');
},
success : function(data) {
console.log('success', data)
$('ul').append('<li>' + JSON.stringify(data) + '</li>');
}
});
Demo: Fiddle
Upvotes: 3