如何用 C 语言编写 AJAX 服务器端脚本?

发布于 2024-07-15 22:10:14 字数 223 浏览 6 评论 0 原文

我是第一次研究 AJAX,我想知道是否可以从用 C 编写的服务器端 CGI 应用程序发出请求?

C 应用程序是否仅使用 printf 来获取数据,类似于 this< /a> .asp 示例?

I am looking into AJAX for the first time and I would like to know if it's possible to make the requests from a server side CGI application written in C?

Will the C application just use printf for the data, similar to this .asp example?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

恍梦境° 2024-07-22 22:10:15

您可以使用 C 语言编写脚本。

看看 http://bellard.org/tcc/ - 这个是一个适用于 Windows 和 UNIX 的小型 C99 编译器。
它有一个独特的功能:“-run”选项。 使用此选项,tinycc 将代码编译到内存中并执行它,而无需创建中间二进制文件。 因此,您需要做的就是像这样创建 CGI 文件:


#!path-to-tinycc-executable -run

// your C code gets below

....

但是,我必须同意之前的评论者的观点,即 C 不是非常适合服务器端 CGI。

You can do scripting using C.

Take a look at http://bellard.org/tcc/ - this is a small C99 compiler for Windows and UNIX.
It has a unique feature: "-run" option. With this option, tinycc compiles the code into memory and executes it without creating an intermediate binary. Thus all you need to do is to create your CGI files like this:


#!path-to-tinycc-executable -run

// your C code goes below

....

However, I have to agree with previous commenters that C is not great for server side CGI.

人事已非 2024-07-22 22:10:15

我是第一次研究 AJAX,我想知道是否可以从用 C 编写的服务器端 CGI 应用程序发出请求?

我会跟上潮流,并说使用另一种语言通常更容易。 然而,我也明白有时你必须使用C - 即,对于资源有限的嵌入式服务器。 如果这是强烈建议您使用 cgic,或者哎呀,甚至可能是像 klone。 不过,我有点偏向后者。 它提供了一个很好的接口来获取请求对象,几乎就像各种脚本框架一样。

I am looking into AJAX for the first time and I would like to know if it's possible to make the requests from a server side CGI application written in C?

I'll hop on the bandwagon, and say that it's usually easier to just use another language. However, I also understand that sometimes you have to use C - i.e., for embedded servers with limited resources. If that's the strongly suggest you use cgic, or heck, maybe even a framework like klone. I'm a bit biased towards the latter, though. It provides a nice interface to getting request objects, almost like the scripting variety of frameworks.

鼻尖触碰 2024-07-22 22:10:14

如果我是你,我会远离 C 来处理服务器端的事情。 有很多其他语言更适合于此,但如果您坚持,您可以使用像 cgic 这样的库。 基本上,您只需使用来自 Apache 等服务器的 CGI 处理程序,但是请使用 C 以外的其他内容。如果落入坏人之手,尤其是通过 CGI,这是非常危险的。

使用 PHP 或 Perl 之类的东西来让自己保持理智。 PHP 对于刚刚入门的人来说是完美的,您不必费力地进行编译并使您的 CGI 处理程序工作/安全。

If I were you, I would stay away from C for server-side stuff. There are so many other languages that are better suited for this, but if you insist, you could use a library like cgic. Basically, you would just use the CGI handler from a server like Apache, but please, PLEASE use something other than C. It's very dangerous in the wrong hands, especially via CGI.

Use something like PHP or Perl to keep yourself sane. PHP is perfect for someone just starting out, and you won't have to futz around with compilation and making your CGI handler work/be secure.

一指流沙 2024-07-22 22:10:14

ASP 做了一些魔法,例如输出适当的响应标头,但除此之外它确实就是这么简单。 AJAX 的服务器端只是响应请求。 以预期的格式输出正确的数据就完成了。 坚持 REST 原则,这会变得很容易。

ASP does some magic, such as outputting the appropriate response headers, but other than that it really is that simple. The server-side of AJAX is just responding to requests. Output the right data in the expected format and you're done. Stick with REST principles and this becomes easy.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文