在function lb(i)中加入alert(x_url)能得到正确的值"bbs_get_grouplist?gn=1&lb=1"
但ajax传回来的值始终是"aaaaaaaaaaa",不知道是什么原因。
main(){
printf("%s","Content-type:text/html;charset=UTF-8;\n\n");
if(getenv("CONTENT-LENGTH")){
int n=atoi(getenv("CONTENT_LENGTH"));
printf("%d",n);
}
else{
printf("%s","aaaaaaaaaaa");
}
}
function lb(i){
var x_lb=document.getElementById("bbs_group1").value;
var x_url="bbs_get_grouplist?gn="+i+"&lb="+x_lb;
if(!req)requestCreate();
if(req){
req.open("GET" , x_url , true);
req.onreadystatechange=function(){if(req.readyState==4 && req.status==200)alert(req.responseText);}
req.send(null);
}
}GET方法直接读取
QUERY_STRING即可POST时候再检查CONTENT_LENGTH给你一个c写的cgi demo,关于环境变量的,应该对一有用.
// cgi-demo.c: Simple CGI demo program.
// Vers. 2.00 - 04.April 2007
// k.d.walter@t-online.de
// Includes
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main (int argc, char *argv[])
{
char *pEnvPtr;
printf ("Content-type: text/html\n");
printf ("\n");
printf ("<HTML>\n");
printf ("<HEAD>\n");
printf ("<TITLE>CGI Environment Variable</TITLE>\n");
printf ("</HEAD>\n");
printf ("<BODY>\n");
// SERVER_SOFTWARE
pEnvPtr= getenv ("SERVER_SOFTWARE");
printf ("SERVER_SOFTWARE= ");
if (!pEnvPtr)
printf ("<NULL-POINTER>\n");
else
printf ("%s\n", pEnvPtr);
printf ("<br>\n");
// SERVER_NAME
pEnvPtr= getenv ("SERVER_NAME");
printf ("SERVER_NAME= ");
if (!pEnvPtr)
printf ("<NULL-POINTER>\n");
else
printf ("%s\n", pEnvPtr);
printf ("<br>\n");
// SERVER_PROTOCOL
pEnvPtr= getenv ("SERVER_PROTOCOL");
printf ("SERVER_PROTOCOL= ");
if (!pEnvPtr)
printf ("<NULL-POINTER>\n");
else
printf ("%s\n", pEnvPtr);
printf ("<br>\n");
// SERVER_PORT
pEnvPtr= getenv ("SERVER_PORT");
printf ("SERVER_PORT= ");
if (!pEnvPtr)
printf ("<NULL-POINTER>\n");
else
printf ("%s\n", pEnvPtr);
printf ("<br>\n");
// REQUEST_URI
pEnvPtr= getenv ("REQUEST_URI");
printf ("REQUEST_URI= ");
if (!pEnvPtr)
printf ("<NULL-POINTER>\n");
else
printf ("%s\n", pEnvPtr);
printf ("<br>\n");
// REQUEST_METHOD
pEnvPtr= getenv ("REQUEST_METHOD");
printf ("REQUEST_METHOD= ");
if (!pEnvPtr)
printf ("<NULL-POINTER>\n");
else
printf ("%s\n", pEnvPtr);
printf ("<br>\n");
// GATEWAY_INTERFACE
pEnvPtr= getenv ("GATEWAY_INTERFACE");
printf ("GATEWAY_INTERFACE= ");
if (!pEnvPtr)
printf ("<NULL-POINTER>\n");
else
printf ("%s\n", pEnvPtr);
printf ("<br>\n");
// HTTP_CONNECTION
pEnvPtr= getenv ("HTTP_CONNECTION");
printf ("HTTP_CONNECTION= ");
if (!pEnvPtr)
printf ("<NULL-POINTER>\n");
else
printf ("%s\n", pEnvPtr);
printf ("<br>\n");
// PATH_INFO
pEnvPtr= getenv ("PATH_INFO");
printf ("PATH_INFO= ");
if (!pEnvPtr)