cgi+ajax+sqlite3返回值为空的有关问题
cgi+ajax+sqlite3返回值为空的问题!
为什么我用ajax请求sqlite3中的数据,返回值为空啊?刚接触求教啊!!
数据库是这样的:
1|n|2014-11-07 15:01:32
2|y|2014-11-07 15:01:45
…………
这是我用cgi写的返回代码!
jiaju.cgi:
这是我写的js代码,alert(xhr.responseText)为空?但换个简单的cgi代码就有返回值了!!
简单cgi代码
test.cgi:
------解决思路----------------------
浏览器直接访问cgi-bin/jiaju.cgi看得到什么内容。。ajax得到和浏览器直接访问后查看源代码得到的一样
如果浏览器直接访问没有数据就是你cgi有问题了。。
为什么我用ajax请求sqlite3中的数据,返回值为空啊?刚接触求教啊!!
数据库是这样的:
1|n|2014-11-07 15:01:32
2|y|2014-11-07 15:01:45
…………
这是我用cgi写的返回代码!
jiaju.cgi:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cgic.h"
#include <unistd.h>
#include <sqlite3.h>
extern char *cgiQueryString;
int cgiMain()
{
cgiHeaderContentType("text/html");
sqlite3 *pdb;
char *perrmsg;
char **resultp = NULL;
int nrow = 0,ncolumn = 0;
if(sqlite3_open("project.db",&pdb) != SQLITE_OK)
{
fprintf(stderr,"open project.db : %s \n",sqlite3_errmsg(pdb));
exit(EXIT_FAILURE);
}
if(sqlite3_get_table(pdb,"select move,time from jiaju where id='2';",&resultp,&nrow,&ncolumn,&perrmsg) != SQLITE_OK)
{
fprintf(stderr,"error : %s\n",perrmsg);
exit(EXIT_FAILURE);
}
if(strcmp(resultp[ncolumn],"y") == 0)
{
fprintf(cgiOut,"%s","resultp[ncolumn + 1]");
}
sqlite3_free_table(resultp);
sqlite3_free(perrmsg);
sqlite3_close(pdb);
return 0;
}
这是我写的js代码,alert(xhr.responseText)为空?但换个简单的cgi代码就有返回值了!!
function createXHR()
{
var xhr;
try{
xhr = new ActiveXObject("Msxm12.XMLHTTP");
}catch(e){
try{
xhr = ActiveXObject("Microsoft.XMLHTTP");
}catch(E){
xhr = false;
}
}
if(!xhr && typeof XMLHttpRequest != 'undefined'){
xhr = new XMLHttpRequest();
}
return xhr;
}
function test()
{
xhr = createXHR();
if(xhr){
xhr.onreadystatechange = callbackFunction;
xhr.open("GET","cgi-bin/jiaju.cgi?cur_time="+new Date().getTime(),false);
xhr.send(null);
}
else{
alert("浏览器不支持,请更换浏览器!");
}
}
function callbackFunction()
{
if(xhr.readyState == 4)
{
alert(xhr.status);
if(xhr.status == 200)
{
var returnValue = xhr.responseText;
alert(xhr.responseText);
if(returnValue != null && returnValue.length > 0)
{
document.getElementById("a").innerHTML = returnValue;
document.getElementById("tv").src = "images/red.png";
}
else
{
alert("结果为空!");
}
}
else
{
alert("画面异常!");
}
}
}
简单cgi代码
test.cgi:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cgic.h"
#include <time.h>
extern char *cgiQueryString;
int cgiMain()
{
time_t current;
struct tm *timeinfo;
time(¤t);
timeinfo = localtime(¤t);
cgiHeaderContentType("text/html");
fprintf(cgiOut,"%s",asctime(timeinfo));
return 0;
}
------解决思路----------------------
浏览器直接访问cgi-bin/jiaju.cgi看得到什么内容。。ajax得到和浏览器直接访问后查看源代码得到的一样
如果浏览器直接访问没有数据就是你cgi有问题了。。