我在一台笔记本电脑上本地运行Parse-Server,我试图使用第二台笔记本电脑的JavaScript访问它。我可以使用终端:
从第二台计算机上的follow curl命令访问Parse-Servercurl -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>
&#13;
我已经尝试了我能想到的一切。谢谢!
答案 0 :(得分:0)
您的Parse服务器URL应该只是根URL:
Parse.serverURL = 'http://192.168.1.16:1337/parse/';
JS客户端将为您构建最终的URL(/classes/GameScore
)。
答案 1 :(得分:0)
抓住它。我需要:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
&#13;
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>
&#13;