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. I know you can use Java Server Pages to call java methods on the se开发者_C百科rver with javascript. 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?
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.
You can fire asynchronous HTTP requests in JavaScript using XMLHttpRequest
, the core technique behind "Ajax". The w3schools provides a concise introduction to 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.
That said, Java Server Pages is absolutely not to be compared with JavaScript. 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. It runs all on the server machine, produces a HTML page and sends it over HTTP to the client side. The C++/C#/NET counterpart of JSP is ASP.
精彩评论