Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top