Reputation: 179
I am trying to use the Parse REST API to send push notifications but whenever I try and make an AJAX call, I get back an invalid JSON error in the response and a 400
status code. Here is my request
$.ajax({
url: 'https://api.parse.com/1/push',
headers: {
"X-Parse-Application-Id": "apID",
"X-Parse-REST-API-Key": "restKey",
"Content-Type": "application/json"
},
data: {
"where": {
"appName": "CampMo"
},
"data": {
"alert": "Test notification"
}
},
error: function(e) {
console.log(e);
},
success: function(data) {
alert("success!");
},
type: 'POST'
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
The request works fine when I do it with a client like Postman but not when I am trying to do it through my web app. Is there something I am missing?
Upvotes: 2
Views: 1480
Reputation: 115212
Pass your data as JSON stringified data
$.ajax({
url: 'https://api.parse.com/1/push',
headers: {
"X-Parse-Application-Id": "apID",
"X-Parse-REST-API-Key": "restKey",
"Content-Type": "application/json"
},
data: '{"where": {"appName": "CampMo"},"data":{"alert":"Test notification" }}',
error: function(e) {
console.log(e);
},
success: function(data) {
alert("success!");
},
type: 'POST'
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
Upvotes: 1