1. Modify the httpd.conf configuration
<ifmodule alias_module>
scriptalias/cgi-bin/"/usr/local/apache2/cgi-bin/"
</IfModule>
。。
<directory "/usr/local/apache2/cgi-bin" >
AllowOverride None
Options None
Order Allow,deny
Allow from all
</Directory>
2. Test code
Index.html
<meta http-equiv= "Content-type" content= "Text/html;charset=utf-8"/>
<script type= "Text/javascript" src= "Js/jquery-1.11.3.min.js" ></script>
<script type= "Text/javascript" src= "Js/test.js" ></script>
<body>
<form>
</form>
<form>
<p>Get<br>
Value: <input id= "GetValue" disabled= "true" ><br>
<input type= "button" id= "Get_value" value= "Get" >
</form>
<form>
<p>Put<br>
Value: <input id= "Postvalue" ><br>
<input type= "button" id= "Post_value" value= "POST" >
</form>
</body>
Test.js
$ (document). Ready (function () {
$ ("#post_value"). Click (function () {
$.ajax ({
Type: "Post",
URL: "cgi-bin/test.cgi",
ContentType: "Text",
DataType: "Text",
Data: "Value=" +$ ("#postValue"). Val (),
Error:function (Result) {
Alert ("Error:get data Fail");
},
Success:function (Result) {
$ ("#getValue"). Val (result);
}
});
});
$ ("#get_value"). Click (function () {
$.ajax ({
Type: "Get",
URL: "cgi-bin/test.cgi",
DataType: "",
Data: "Value",
Error:function (Result) {
Alert ("Error:get data Fail");
},
Success:function (Result) {
$ ("#getValue"). Val (result);
}
});
});
});
Push in Test.cpp
The generated test.cgi is placed under/usr/local/apache2/cgi-bin/
Apache2 CGI Demo