日期:2014-05-16  浏览次数:20422 次

Ext store无法得到后台传的数据
Store里面没有数据,但是直接访问后台处理程序的话有数据的
JScript code

<script type="text/javascript">
    Ext.onReady(function(){
    var cum = new Ext.grid.ColumnModel([
    {header:'ID',dataIndex:'id'},
    {header:'adValue',dataIndex:'adValue'},
    {header:'adTime',dataIndex:'adTime'}
    ]);
    var store = new Ext.data.JsonStore({                                        proxy:new Ext.data.HttpProxy({url:'http://192.168.0.9/showAll.cgi'}),
        reader:new Ext.data.JsonReader({totalProperty:'totalProperty',root:'root'},[{name:'id'},{name:'adValue'},{name:'adTime'}])
    });
    //store.load();
    alert(store.getCount());//这个地方显示为0
    var cumgrid = new Ext.grid.GridPanel({
        renderTo:'cumGrid',
        store:store,
        viewConfig:{
            forceFit:true
        },
        autoHeight:true,
        autoWidth:true,
        cm:cum,
        bbar:new Ext.PagingToolbar({
            pageSize:10,
            autowidth:true,
            store:store,
            displayInfo:true,
            emptyMsg:'no record'
        })
    });
});
</script>




C/C++ code

#include "sqlite3.h"
#include <stdio.h>
int  main(void)
{
    printf("Content-Type:text/html;charset=gb2312\n\n");
//    printf("<html>\n<body>\n");
    sqlite3 *db;
    char *zErrMsg = 0;
    int rc;
    char *sql = "select * from tempture limit 20;";
    char result[1024]="{totalProperty:20,root:[";
    char ** tableResult;
    int nRow,nColumn;
    int i,j,index;
    rc = sqlite3_open("envDB",&db);
//    printf("<table>\n<tr><td>ID</td><td>ADVALUE</td><td>ADTIME</td></tr>\n");
//    printf("%d%d",rc,SQLITE_OK);
    if(rc)
    {
        fprintf(stdout,"Can't opendb:%s\n ",sqlite3_errmsg(db));
        sqlite3_close(db);
        exit(1);    
    }
    rc = sqlite3_get_table(db,sql,&tableResult,&nRow,&nColumn,&zErrMsg);
    if(SQLITE_OK == rc)
    {
        index = nColumn;
        for(i = 0;i < nRow;i++)
        {
//        printf("<tr>");
/*            for(j =0;j < nColumn;j++)
            {
                printf("<td>%s</td>",tableResult[index]);
                index++;    
            }
*/
        strcat(result,"{id:");
        strcat(result,tableResult[index]);
        strcat(result,",");
        index++;
        strcat(result,"adValue:");
        strcat(result,tableResult[index]);
        strcat(result,",");
        index++;
        strcat(result,"adTime:");
        strcat(result,tableResult[index]);
        if((i+1) == nRow){
            strcat(result,"}");
        }else{
            strcat(result,"},");
        }
        index++;
//        printf("</tr>\n");        
        }
        strcat(result,"]}");
    }
    sqlite3_free_table(tableResult);
    sqlite3_close(db);
    printf("%s",result);
//    printf("</table>\n");
//    printf("</body>\n"); 
//    printf("</html>\n"); 
    return 0;    
}



直接访问http://192.168.0.9/showAll.cgi'得到的数据格式为{totalProperty:20,root:[{id:883,adValue:413 ,adTime:2012-07-08 21:20:01},{id:884,adValue:409 ,adTime:2012-07-08 21:20:01},{id:885,adValue:411 ,adTime:2012-07-08 21:20:02},{id:886,adValue:407 ,adTime:2012-07-08 21:20:02},{id:887,adValue:406 ,adTime:2012-07-08 21:20:03},{id:888,adValue:409 ,adTime:2012-07-08 21:20:03},{id:889,adValue:413 ,adTime:2012-07-08 21:20:04},{id:890,adValue:402 ,adTime:2012-07-08 21:20:04},{id:891,adValue