我正在尝试使用Parse REST API发送推送通知,但每当我尝试进行AJAX调用时,我都会在响应和400
状态代码中找回无效的JSON错误。这是我的要求
$.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>
&#13;
当我使用像Postman这样的客户端执行此请求时,该请求正常,但在我尝试通过我的Web应用程序执行时,请求无效。有什么我想念的吗?
答案 0 :(得分:1)
将您的数据作为JSON字符串化数据传递
$.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>