2015-09-18 102 views
1

我一直在使用Parse多年来将推送通知发送到我的iOS应用程序,并且它工作得很好。通过网站发送解析推送通知

我现在希望能够做同样的事情 - 但从我自己的网页。这意味着,我只想进入常规网页(我将创建它),在文本框中输入一些文本,然后按下按钮 - 并将该文本作为推送通知发送到我的iOS应用程序。

我试过下面的代码 - 至今没有运气:

<html> 
<head> 
<title>PN TEST</title> 

<script type="text/javascript" src="jquery-1.7.2.js"></script> 
<script type="text/javascript" src="http://www.parsecdn.com/js/parse-1.2.0.min.js"></script> 

<script type="text/javascript"> 

Parse.initialize("xxxxxxxxxxxxx", "xxxxxxxxxxxxxxx"); 

function makePushNotification() { 
    alert ('sending a push!'); 

    $.ajax({ 
      type: 'POST', 
      headers: { 'X-Parse-Application-Id’ : ‘xxxxxxxxxxxxxxxxxxxxxxxx’ , 'X-Parse-REST-API-Key’ : ‘xxxxxxxxxxxxxxxxxxxxxxxxxxx' }, 
      url: "https://api.parse.com/1/push", data: '{"channel": "", "data": {"alert": "Sending a Push Notification from my web page."} }', 
      contentType: "application/json" 
     }); 
} 


</script> 

</head> 


<body> 
    Enter your push notification: <br/> 

    <form id="testForm"> 
     <textarea cols="60" rows="4" id="textAreaText"></textarea> 
      <br/> 
     <input type="button" value="Send Push Notification" onclick="makePushNotification()" /> 
      <br/> 
    </form> 

</body> 
</html> 

(很显然,我硬编码的推送通知的实际文本这里,而不是真正从textarea箱阅读它 - 但这只是现在。)

无论如何,任何想法这是什么缺失?

回答

0

contentType:“application/json”应该是标题。

'Content-Type': 'application/json' 
+0

你的意思是它应该放在JSON的'headers'部分上面呢?意思在这里:'标题:{'X-Parse-Application-Id':'xxxxxxxxxxxxx' ...'? – Sirab33

+0

我做了你的建议,并得到这个错误:'[错误]无法加载资源:请求标头字段contentType不被Access-Control-Allow-Headers所允许。 (推,第0行)' – Sirab33

+0

@ Sirab33它应该是'内容类型'就像我在我的答案。 –