当前位置: 代码迷 >> Ajax >> Extjs获取不到靠山回传的json数据
  详细解决方案

Extjs获取不到靠山回传的json数据

热度:755   发布时间:2014-02-27 01:51:38.0
Extjs获取不到后台回传的json数据
前台Extjs代码:

Ext.onReady(function () {

            var store = new Ext.data.Store({
                proxy: new Ext.data.HttpProxy({ url: "/WebService/test/tb_data.ashx" }),
                reader: new Ext.data.JsonReader({
                    totalProperty: "results",
                    root: "jsonObjs"
                },
                                 [
                                   { name: 'user_name' },
                                   { name: 'user_id' },
                                   { name: 'ssyj' }
                                 ]
                           ),
                listeners: {
                    load: function () {
                        alert(store.getCount());
                    }
                }
            });

            store.load();

        });

后台代码:

public void ProcessRequest(HttpContext context)
        {
            context.Request.ContentEncoding = Encoding.GetEncoding("UTF-8");

            context.Response.ContentEncoding = Encoding.GetEncoding("UTF-8");

            context.Response.Charset = "UTF-8";

            context.Response.ContentType = "text/plain";

            string result = string.Empty;

            string ygk_list = string.Empty;

            string strSQL = string.Empty;

            try
            {
                strSQL = string.Format(@"select tb_user.user_name,tb_fwcjqr.user_id,sum(tb_fwcjqr.htzj)as ssyj   from tb_fwcjqr
inner join tb_user on tb_user.id = tb_fwcjqr.user_id
group by tb_user.user_name ,tb_fwcjqr.user_id");

                DataTable dt = LTP.DBUtility.DbHelperSQL.Query(strSQL).Tables[0];

                if (dt.Rows.Count > 0)
                {
                    result = LTP.BLL.Ext_Json.DataTable2Json(dt);
                }
                else
                {
                    result = "false";
                }