当前位置: 代码迷 >> Ajax >> extjs用ajax获取json数据不能转换成Store,该怎么处理
  详细解决方案

extjs用ajax获取json数据不能转换成Store,该怎么处理

热度:266   发布时间:2013-01-08 14:02:13.0
extjs用ajax获取json数据不能转换成Store
本帖最后由 showbo 于 2012-12-20 09:05:42 编辑
前台代码:
Ext.onReady(function () {
            var store = new Ext.data.Store({
                fields: [{ name: 'user_id' }, { name: 'user_name' }, { name: 'ssyj', type: "float"}],
                reader: new Ext.data.JsonReader({ totalProperty: "results", root: 'data' })
//                listeners: {
//                    load: function () {
//                        alert(store.getCount());
//                    }
//                }
            });
            var requestConfig = {
                url: '/WebService/test/tb_data.ashx', //请求的服务器地址
                params: { userName: 'tom', password: '123' }, //请求参数
                customer: '自定义属性', //附加属性
                callback: function (options, success, response) {//回调函数
                    alert(response.responseText);
                    var forminfo = Ext.decode(response.responseText);
                    store.loadData(Ext.JSON.decode(response.responseText,true));
                    alert(store.getCount());
                }
            }
            Ext.Ajax.request(requestConfig); //发送请求

返回的json数据字符串:
{"results":3,"data":[
{"user_name":"郑正英","user_id":"10","ssyj":"39569.0100"},
{"user_name":"王雪梅","user_id":"11","ssyj":"557619.9900"},
{"user_name":"张丹青","user_id":"12","ssyj":"116000.0000"},
{"user_name":"张海东","user_id":"13","ssyj":"1412742.9900"}]}

后台代码:

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

            context.Response.ContentEncoding = Encoding.GetEncoding("UTF-8");
  相关解决方案