开发者

Implementing a very small HTTP server in c/c++ and want to use AJAX

I want to have a dynamic webpage that automaticly开发者_如何学编程 updates some information, this information should be received from my c/c++ application using HTTP. I have set up a socket and can send HTML and Javascript files to the browser.

I don't know how to move on. How to encapsulate my data into XMLHttpRequest objects? Or maybe this isn't the way to go? The problem is that my c/c++ application will be run on an embedded system that can't really support php or something like that.

I can't really understand how XMLHttpRequest works, I only find a lot of client examples on the web and not much about how a server should handle it.


A server should handle it as any other request. From the servers point of view, it's a normal HTTP request. Return the data that the client asks for! This is usually a HTML fragment, some XML or some JSON.


Ajax just send normal HTTP GET POST ... request, you should make sure your response header is correct, such as Content-Type.


How do you send information to the browser? The browser is client-side. To get information, you must either query the server (which you say is written in C++). If you want your client to receive request, you should probably emulate a server-like behavior using NodeJS.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜