2017-09-17 118 views
0

我試圖設置一個簡單的測試網頁來執行一些雲代碼,從Parse發送推送通知。我使用back4app.com。以下是我迄今爲止:解析Javascript和雲代碼

JS:

Parse.initialize('APP_ID'); 
Parse.serverUrl = 'https://parseapi.back4app.com/'; 

function sendPushNotification() { 

    let messageBox = document.getElementById('messageBox'); 
    let messageToPush = messageBox.value; 

    Parse.Cloud.run("sendPushNotification", { message: messageToPush }).then(function(result) { 
     console.log("result: " + JSON.stringify(result)); 
    }, function(error) { 
     console.log("Error: " + JSON.stringify(error)); 
    }); 
} 

HTML:

<!DOCTYPE html> 
<html> 
    <head> 
     <meta charset="UTF-8"> 
     <title>title</title> 
     <script src="https://unpkg.com/parse/dist/parse.min.js"></script> 
     <script src="main.js"></script> 
    </head> 
    <body> 
      Message to Push:<br> 
      <input id="messageBox" type="text" /><br> 
      <input type="button" value="Push" onclick="sendPushNotification()" /> 
    </body> 
</html> 

但是當我添加一些文本到文本框中,我得到這些錯誤:

[Error] Failed to load resource: The certificate for this server is invalid. You might be connecting to a server that is pretending to be 「api.parse.com」 which could put your confidential information at risk. (sendPushNotification, line 0) 

什麼問題?在分析開發商JS指南,它說:

要初始化自己的解析,服務器使用Javascript,你應該 這個

Parse.initialize("YOUR_APP_ID"); 
Parse.serverURL = 'http://YOUR_PARSE_SERVER:1337/parse' 

替換當前的初始化代碼我用back4app網址我在我的iOS應用程序中使用。如此混亂

回答

0

請確保您按照下面這樣的結構:

Parse.initialize("YOUR_APP_ID", "YOUR_JAVASCRIPT_KEY"); 
Parse.serverURL = 'https://parseapi.back4app.com' 
+0

我試過了也,但它有同樣的錯誤 – Minebomber

+0

你在你的代碼「Parse.serverUrl」,但你應該使用而不是「Parse.serverURL」 –