简体   繁体   English

将C ++后端连接到Javascript

[英]Connecting C++ backend to Javascript

I was hoping to make a website that displays a google map with points based of information returned by a C++ function. 我希望建立一个网站,以显示带有C ++函数返回信息的点的google map。 I know you can use Java Server Pages to call java methods on the server with javascript. 我知道您可以使用Java Server Pages使用javascript调用服务器上的java方法。 Would there be a way to connect C++ code on the server with javascript in order to produce the same result as java server pages? 是否有一种方法可以使用javascript连接服务器上的C ++代码,以产生与java服务器页面相同的结果?

Since JavaScript runs at a completely different environment which is separated from the webserver by a HTTP connection, your best bet is to fire a HTTP request to the server side on a specific URL which has the particular C++ code attached. 由于JavaScript在完全不同的环境中运行,该环境通过HTTP连接与Web服务器分隔开,因此,最好的选择是在附加了特定C ++代码的特定URL上向服务器端发送HTTP请求。

You can fire asynchronous HTTP requests in JavaScript using XMLHttpRequest , the core technique behind "Ajax" . 您可以使用XMLHttpRequest“ Ajax”背后的核心技术)在JavaScript中触发异步HTTP请求。 The w3schools provides a concise introduction to Ajax. w3schools提供了有关Ajax的简要介绍 To make it all less verbose and bloated, you may consider to grab the jQuery library which has under each an $.ajax function for this purpose. 为了使它不再那么冗长和and肿,您可以考虑使用jQuery库,为此,它在每个$.ajax函数下都有一个。


That said, Java Server Pages is absolutely not to be compared with JavaScript . 就是说,绝对不要将Java Server PagesJavaScript进行比较。 JSP is a Java based server side view technology which provides a template to write HTML/CSS/JS in and offers capabilities to control the page flow dynamically and interact with backend Java code using taglibs and expression language. JSP是基于Java的服务器端视图技术,它提供了一个模板来编写HTML / CSS / JS,并提供了使用taglibs和表达式语言动态控制页面流以及与后端Java代码进行交互的功能。 It runs all on the server machine, produces a HTML page and sends it over HTTP to the client side. 它全部在服务器计算机上运行,​​生成HTML页面,并通过HTTP将其发送到客户端。 The C++/C#/NET counterpart of JSP is ASP . 与JSP相对应的C ++ / C#/ NET是ASP

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM