簡體   English   中英

在JavaScript中本地使用Parse-Server

[英]Using Parse-Server locally with JavaScript

我在一台筆記本電腦上本地運行了Parse-Server,並且試圖從另一台筆記本電腦使用JavaScript對其進行訪問。 我可以使用終端從第二台計算機上使用follow curl命令訪問Parse-Server:

curl -X POST -H "X-Parse-Application-Id: APPID123" -H "Content-Type: application/json" -d '{"score":1341,"playerName":"P MUR","cheatMode":false}' http://192.168.1.16:1337/parse/classes/GameScore

但是,我似乎無法弄清楚如何使用JavaScript進行同樣的操作。 這是不起作用的代碼:

 <!doctype html> <html> <head> <meta charset="UTF-8"> <title>Untitled Document</title> <script src="//www.parsecdn.com/js/parse-1.6.14.min.js"></script> <script> Parse.initialize("APPID123"); Parse.serverURL = 'http://192.168.1.16:1337/parse/classes/GameScore'; var GameScore = Parse.Object.extend("GameScore"); var gameScore = new gameScore(); gameScore.save({playerName: "Pete"}).then(function(object) { alert("yay! it worked"); }); </script> </head> <body> </body> </html> 

我已經嘗試了所有我能想到的。 謝謝!

您的Parse服務器網址應該只是根網址:

Parse.serverURL = 'http://192.168.1.16:1337/parse/';

JS客戶端將為您構造最終URL(使用/classes/GameScore )。

抓到了 我需要:

  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 

DMan也是正確的。 現在工作正常。 我不確定為什么在此代碼中需要jQuery,但是,不管用什么。 謝謝大家!

這是有效的代碼:

 <!doctype html> <html> <head> <meta charset="UTF-8"> <title>Untitled Document</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script type="text/javascript" src="http://www.parsecdn.com/js/parse-latest.js"></script> <script> Parse.initialize("APPID123"); Parse.serverURL = 'http://192.168.1.16:1337/parse'; var GameScore = Parse.Object.extend("GameScore"); var gameScore = new GameScore(); gameScore.save({playerName: "Pete"}).then(function(object) { alert("yay! it worked"); }); </script> </head> <body> </body> </html> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM