The HTML code: (index.php)
-
<html>
-
<head>
-
<script type="text/javascript" src=""></script>
-
<script type="text/javascript" src="20120721.js"></script>
-
</head>
-
<body>
-
<div id="loginContent" class="container">
-
<div id="loginResult" style="display:none;">
-
</div>
-
<form id="loginForm" name="loginForm" method="post" action="">
-
<fieldset>
-
<legend>Enter information</legend>
-
<p>
-
<label for="firstname">First name</label>
-
<br />
-
<input type="text" id="firstname" name="firstname" class="text" size="20" />
-
</p>
-
<p>
-
<label for="name">Name</label>
-
<br />
-
<input type="test" id="name" name="name" class="text" size="20" />
-
</p>
-
<p>
-
<button type="submit" class="button positive">
-
Login
-
</button>
-
</p>
-
</fieldset>
-
</form>
-
</div>
-
</body>
-
</html>
The JavaScript Code: (20120721.js)
-
$(document).ready(function(){
-
$("form#loginForm").submit(function() { // loginForm is submitted
-
-
-
var firstname = $('#firstname').attr('value'); // get first name
-
var name = $('#name').attr('value'); // get name
-
-
if (firstname && name) { // values are not empty
-
$.ajax({
-
type: "GET",
-
url: "/cgi-bin/test.fcg", // URL of the Perl script
-
-
// send firstname and name as parameters to the Perl script
-
data: "firstname=" + firstname + "&name=" + name,
-
-
// script call was *not* successful
-
error: function() {
-
alert("script call was not successful");
-
},
-
-
// script call was successful
-
// perl_data should contain the string returned by the Perl script
-
success: function(perl_data){
-
alert("Your name is: " + perl_data)
-
}
-
});
-
}
-
-
else {
-
$('div#loginResult').text("Enter your name");
-
$('div#loginResult').addClass("error");
-
}
-
-
$('div#loginResult').fadeIn();
-
return false;
-
});
-
});
The C code: (test.c)
-
#include "fcgi_stdio.h"
-
#include <stdio.h>
-
#include <stdlib.h>
-
#include <stddef.h>
-
#include <time.h>
-
int main(void)
-
{
-
while (FCGI_Accept() >= 0) {
-
int a=100;
-
int b=200;
-
printf("Content type: text/html\n\n");
-
//printf("%s",a);
-
printf("%s",getenv("REQUEST_METHOD"));
-
printf("|"); //输出“|”作为分隔ab值
-
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
-
-
}
-
}
[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
阅读(844) | 评论(0) | 转发(0) |