Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6660589
  • 博文数量: 1159
  • 博客积分: 12444
  • 博客等级: 上将
  • 技术积分: 12570
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-13 21:34
文章分类

全部博文(1159)

文章存档

2016年(126)

2015年(350)

2014年(56)

2013年(91)

2012年(182)

2011年(193)

2010年(138)

2009年(23)

分类: Web开发

2015-11-20 16:25:22

The HTML code: (index.php)

点击(此处)折叠或打开

  1. <html>
  2.   <head>
  3.     <script type="text/javascript" src=""></script>
  4.     <script type="text/javascript" src="20120721.js"></script>
  5.   </head>
  6.   <body>
  7.     <div id="loginContent" class="container">
  8.         <div id="loginResult" style="display:none;">
  9.         </div>
  10.         <form id="loginForm" name="loginForm" method="post" action="">
  11.         <fieldset>
  12.             <legend>Enter information</legend>
  13.             <p>
  14.             <label for="firstname">First name</label>
  15.             <br />
  16.             <input type="text" id="firstname" name="firstname" class="text" size="20" />
  17.             </p>
  18.             <p>
  19.             <label for="name">Name</label>
  20.             <br />
  21.             <input type="test" id="name" name="name" class="text" size="20" />
  22.             </p>
  23.             <p>
  24.             <button type="submit" class="button positive">
  25.              Login
  26.             </button>
  27.             </p>
  28.         </fieldset>
  29.         </form>
  30.     </div>
  31.   </body>
  32. </html>



The JavaScript Code: (20120721.js)

点击(此处)折叠或打开

  1. $(document).ready(function(){
  2.   $("form#loginForm").submit(function() { // loginForm is submitted


  3. var firstname = $('#firstname').attr('value'); // get first name
  4. var name = $('#name').attr('value'); // get name

  5. if (firstname && name) { // values are not empty
  6.     $.ajax({
  7.         type: "GET",
  8.         url: "/cgi-bin/test.fcg", // URL of the Perl script

  9.         // send firstname and name as parameters to the Perl script
  10.         data: "firstname=" + firstname + "&name=" + name,

  11.         // script call was *not* successful
  12.         error: function() {
  13.             alert("script call was not successful");
  14.         },

  15.         // script call was successful
  16.         // perl_data should contain the string returned by the Perl script
  17.         success: function(perl_data){
  18.             alert("Your name is: " + perl_data)
  19.         }
  20.     });
  21. }

  22. else {
  23.   $('div#loginResult').text("Enter your name");
  24.   $('div#loginResult').addClass("error");
  25. }

  26. $('div#loginResult').fadeIn();
  27. return false;
  28.   });
  29. });



The C code: (test.c)

点击(此处)折叠或打开

  1. #include "fcgi_stdio.h"
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <stddef.h>
  5. #include <time.h>
  6. int main(void)
  7. {
  8.     while (FCGI_Accept() >= 0) {
  9.         int a=100;
  10.         int b=200;
  11.         printf("Content type: text/html\n\n");
  12.         //printf("%s",a);
  13.         printf("%s",getenv("REQUEST_METHOD"));
  14.         printf("|");                            //输出“|”作为分隔ab值
  15.         printf("%s",getenv("QUERY_STRING"));    //This seems to be working fine with form "GET" method but not with "POST" method. POST data is appended to the request header, after a double newline. In a CGI-BIN environment, you read it from STDIN. http://stackoverflow.com/questions/5451913/how-to-retrieve-form-post-data-via-cgi-bin-program-written-in-c

  16.     }
  17. }

[root@localhost cbpm]# pwd
/var/www/html/cbpm
[root@localhost cbpm]# ls
20120721.js  index.php

[root@localhost cgi-bin]# pwd
/var/www/cgi-bin
[root@localhost cgi-bin]# gcc test.c -o test.fcg -lfcgi

[root@localhost cgi-bin]# uname -a
Linux localhost.localdomain 4.2.1-1.el7.elrepo.x86_64 #1 SMP Mon Sep 21 20:01:19 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux

[root@localhost cgi-bin]# cat /etc/redhat-release
CentOS Linux release 7.1.1503 (Core)

[root@localhost cgi-bin]# systemctl restart httpd.service










阅读(812) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~