英文:
Invoking a Go Server from Java Script code involving Google Maps API
问题
我正在为我的分布式系统课程制作一个使用Go语言演示分布式存储和容错性的项目。后端完全使用Go语言编写,我主要有两个重要的函数Add(Args)和Get(Args)。
我的前端是一个带有Google地图的网页。地图上的事件处理程序将是JavaScript函数。我可以轻松从Google Maps API中提取诸如地图中心或地图框架边界之类的信息。
我的问题是:我不知道如何使用来自JavaScript函数的信息来“调用”后端的Go函数/程序。我对Web开发非常陌生,所以如果这显而易见,我表示歉意。
在搜索时,我找到的唯一方法是将Go程序作为某种http服务器在Google App Engine上运行。不过,我对细节还不确定。
如果有人能给我一些参考资料,或者指点我正确的方向,我会很高兴的!
英文:
I am making a project for my Distributed Systems Class in Go that demonstrates distributed storage and fault tolerance. The back-end is all in GO - I essentially have 2 major functions Add(Args) and Get(Args) in GO.
My front-end is a Web page with Google Maps. The event handlers on the map would be Javascript functions. I can easily extract information like Center of Map, or map frame bounds from the Google Maps API.
My problem is: I don't know how to "call" the GO function/program in the back-end with information from my JavaScript function. I am very new to Web development, so I apologize if this is painfully obvious.
On googling, the only approach I found is running the GO program as some sort of http server on google app engine. I am unsure about the details though.
I'd be happy if someone gives me some references, or points me in the right direction!
答案1
得分: 3
除了一般的ajax通信方式外,从地图到服务器使用GET/POST方法。
虽然有很多库,但其中一个著名的库是jQuery。
1)从官方页面下载jQuery库。
http://jquery.com/
2)部署到appengine。
3)尝试一个简单的代码:
<script src="/js/jquery.min.js"></script>
<script>
jQuery.post("http://yourapp.appspot.com/test/", {
message : "helloworld"
}, function(response){
alert(response);
});
</script>
4)您还需要您的GO脚本来处理对"http://yourapp.appspot.com/test/"的POST访问。
(抱歉,我对GO语言不熟悉)
5)在谷歌上搜索关键词“ajax jQuery”。
希望这些步骤对您有所帮助。
英文:
As well as ajax communication in general way, from the map to the server with GET/POST method.
There are tons of library though, one of the famous library is jQuery.
-
Download jQuery library from official page.
http://jquery.com/ -
Deploy to appengine.
-
Try a simple code:
<script src="/js/jquery.min.js"></script>
<script>
jQuery.post("http://yourapp.appspot.com/test/", {
message : "helloworld"
}, function(response){
alert(response);
});
</script> -
You also need your GO script to process POST access for "http://yourapp.appspot.com/test/".
(Sorry I'm not familiar with GO language, yet) -
Googling keywords "ajax jQuery".
I hope this steps help you.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论