首页 新闻 搜索 专区 学院

在服务器上,后台所有Ext.grid.GridPanel列表数据都显示不出来

1
悬赏园豆:180 [待解决问题]

      最近,用asp.net+extjs做了一个小项目,本地测试通过,发布到服务器空间后,整个后台Ext.grid.GridPanel列表数据都显示不出来,但是后台asp.net的Repeater、DataList等控件列表可以显示数据,而且数据库是有信息的;为什么在服务器上,ext就好像不能访问数据库呢?(注:ext的界面可以显示出来,就数据显示不出来)

简小希的主页 简小希 | 初学一级 | 园豆:5
提问于:2011-11-09 15:55
< >
分享
所有回答(3)
0

光这些信息没用啊。你可以用firebug一类的工具看一下,是请求没发出来,还是返回的没数据,还是返回有数据但是解析/展现错误了。光一个“显示不出来”,怎么查问题。

水牛刀刀 | 园豆:6350 (大侠五级) | 2011-11-09 15:57

嗯,我刚刚去看了一下,有数据,有显示数据大小,访问状态是200 ok ,这是服务器返回的数据:{totalCount:2,success:true,error:"",singleInfo:"",data:[{"id":"18","product_ID":"12","Name":"12","Price":"12.0000","salePrice":"12.0000","Discount":"1","Size":"0","Diameter":"12","Weight":"12","Picture":"2.gif","took":"","desc":"112","stockCount":"0","series":"12","categoty":"12","create_date":"2011-11-08","create_by":"admin","update_date":"2011-11-08","update_by":"admin","status":"0","kill_time":"2011-11-8 18:12:05","kill_count":"0","isKill":"0","Material":"12","purity":"12"},{"id":"17","product_ID":"12","Name":"12","Price":"12.0000","salePrice":"12.0000","Discount":"1","Size":"0","Diameter":"12","Weight":"12","Picture":"01x.jpg","took":"01.png","desc":"12","stockCount":"0","series":"12","categoty":"12","create_date":"2011-11-08","create_by":"admin","update_date":"2011-11-08","update_by":"admin","status":"1","kill_time":"2011-11-8 18:09:53","kill_count":"0","isKill":"0","Material":"12","purity":"12"}],数据是有了,怎么页面不显示呢?

支持(0) 反对(0) 简小希 | 园豆:5 (初学一级) | 2011-11-10 11:22

@简小希: 你确定本地同样的代码测试正常?这个有没有报什么js错误呢?查一下firebug的network列表,是不是有什么资源没有找到。

支持(0) 反对(0) 水牛刀刀 | 园豆:6350 (大侠五级) | 2011-11-10 11:25

@水牛刀刀: {totalCount:2,success:true,error:"",singleInfo:"",data:[{"id":"18","product_ID":"12","Name":"12","Price":"12.0000","salePrice":"12.0000","Discount":"1","Size":"0","Diameter":"12","Weight":"12","Picture":"2.gif","took":"","desc":"112","stockCount":"0","series":"12","categoty":"12","create_date":"2011-11-08","create_by":"admin","update_date":"2011-11-08","update_by":"admin","status":"0","kill_time":"2011-11-08 18:12:05","kill_count":"0","isKill":"0","Material":"12","purity":"12"},{"id":"17","product_ID":"12","Name":"12","Price":"12.0000","salePrice":"12.0000","Discount":"1","Size":"0","Diameter":"12","Weight":"12","Picture":"01x.jpg","took":"01.png","desc":"12","stockCount":"0","series":"12","categoty":"12","create_date":"2011-11-08","create_by":"admin","update_date":"2011-11-08","update_by":"admin","status":"1","kill_time":"2011-11-08 18:09:53","kill_count":"0","isKill":"0","Material":"12","purity":"12"}]},这是我本地的返回的json数据,好像最后多了一个大括号,服务器的少了一个大括号,这是为什么呢?没有报js错误耶,页面全部js访问状态都是200 ok,你说得那个network在哪里呀?

支持(0) 反对(0) 简小希 | 园豆:5 (初学一级) | 2011-11-10 11:41

@简小希: 你本地返回的json格式是对的,服务器上返回的那个json,最后少了个大括号,导致json对象不是闭合的(错误的json格式),可能是这个原因导致的不能解析,因此显示不出来。你服务器端是什么做的?ASP.NET?还是ASP.NET MVC?去查一下把数据转成json返回的方法,看看是不是跟你本地开发是同样的类库。

支持(0) 反对(0) 水牛刀刀 | 园豆:6350 (大侠五级) | 2011-11-10 11:47

@水牛刀刀: 您好,服务器是用asp.net做的,这是转换成json的方法,最后生成一个字符串,这个方法是放在BLL层的,我建了BLL类库,最后解析应该是BLL.dll,这个我放到服务器上啦,为什么会少一个大括号呢?估计就是这个问题了:

  //序列化JSON对象,得到返回的JSON代码
    public override string ToString()
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("{");
        sb.Append("totalCount:" + totlalCount.ToString() + ",");
        sb.Append("success:" + _success.ToString().ToLower() + ",");
        sb.Append("error:\"" + _error.Replace("\"", "\\\"") + "\",");
        sb.Append("singleInfo:\"" + singleInfo.Replace("\"", "\\\"") + "\",");
        sb.Append("data:[");

        int index = 0;
        sb.Append("{");
        if (arrData.Count <= 0)
        {
            sb.Append("}]");
        }
        else
        {
            foreach (string val in arrData)
            {
                index++;

                if (val != "<BR>")
                {
                    sb.Append(val + ",");
                }
                else
                {
                    sb = sb.Replace(",", "", sb.Length - 1, 1);
                    sb.Append("},");
                    if (index < arrData.Count)
                    {
                        sb.Append("{");
                    }
                }

            }
            sb = sb.Replace(",", "", sb.Length - 1, 1);
            sb.Append("]");
        }

        sb.Append("}");
        return sb.ToString();
    }

支持(0) 反对(0) 简小希 | 园豆:5 (初学一级) | 2011-11-10 11:56

@简小希: 奇怪,看你的代码应该不会最后少个大括号才对。你把本地的再编译一下,再发布一次试试。

支持(0) 反对(0) 水牛刀刀 | 园豆:6350 (大侠五级) | 2011-11-10 12:01

@水牛刀刀: 您好,我刚刚重新发布了一次,哎,还是少了一个大括号,本地真的没问题,服务器响应的结果就是少了一个大括号,这问题把我急的,问题是找出来了,可不知道怎么解决了。。。

支持(0) 反对(0) 简小希 | 园豆:5 (初学一级) | 2011-11-10 15:58

@简小希: 你这个ToString执行之后,还有没有那里又操作过json了。还有你看看服务器上web.config里的这个配置:maxJsonLength设置的多少

<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="2147483645" recursionLimit="100">
</jsonSerialization>
</webServices>
</scripting>
</system.web.extensions>

支持(0) 反对(0) 水牛刀刀 | 园豆:6350 (大侠五级) | 2011-11-10 16:06

@水牛刀刀: 您好,我没设置这个喔,这个会影响吗?我先看看

支持(0) 反对(0) 简小希 | 园豆:5 (初学一级) | 2011-11-10 16:08

@简小希: 可能会影响,如果超出了默认的maxJsonLength,后面的就会被截掉(我不知道默认是多大)。你加上,设置长一点是没有关系的。

支持(0) 反对(0) 水牛刀刀 | 园豆:6350 (大侠五级) | 2011-11-10 16:09

@简小希: 好像我也记错了,超出maxJsonLength不知道是会被截掉还是抛异常了……姑且试试看吧。

支持(0) 反对(0) 水牛刀刀 | 园豆:6350 (大侠五级) | 2011-11-10 16:10

@简小希: 如果还是没查出原因,你可以试试其他数据(比如data里只有一条记录或者3条记录),看看是不是还是少一个大括号。

支持(0) 反对(0) 水牛刀刀 | 园豆:6350 (大侠五级) | 2011-11-10 16:13

@水牛刀刀: 

您好,我贴出我的代码来,这是extjs访问的数据的方法: 

     public string JSON = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Login"] == null)
        {
            Response.Redirect("../../Login.aspx");
        }
        if (Request["sreach"] != null)
        {
            GetAllvipUser();
        }
    }
    public void GetAllvipUser()
    {
        string start = Request.Form["start"];
        string limit = Request.Form["limit"];
        if (start != null && start != "" && limit != null && limit != "")
        {
            JSON = vipUserManager.GetAllvipUser(Convert.ToInt32(start), Convert.ToInt32(limit));
            if (JSON != "")
                Response.Write(JSON);
        }
        else
        {
            Response.Write("{success:false}");
        }
        Response.Flush();
        Response.Close();
    }

接着,调用:

 public static string GetAllvipUser(int start, int limit)
        {
            DataSet ds = vipUserService.GetAllvipUser(start, limit);
            return ReturnJSON(ds);
        }
        //返回字符串
        private static string ReturnJSON(DataSet ds)
        {
            JSONHelper json = new JSONHelper();
            string jsons = "";
            json.success = true;
            if (ds.Tables[0].Rows.Count < 1)
                return "";

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                json.AddItem("id", row["id"].ToString());
                json.AddItem("adminName", row["adminName"].ToString());
                json.AddItem("adminPwd", row["adminPwd"].ToString());
                json.AddItem("sex", row["sex"].ToString());
                json.AddItem("last_time", row["last_time"].ToString());
                json.AddItem("create_date", Convert.ToDateTime(row["create_date"]).ToString("yyyy年MM月dd日"));
                json.AddItem("trueName", row["trueName"].ToString());
                json.AddItem("email", row["email"].ToString());
                json.AddItem("mobile", row["mobile"].ToString());
                json.AddItem("telephone", row["telephone"].ToString());
                json.AddItem("vip_state", row["vip_state"].ToString());
                json.AddItem("state", row["state"].ToString());
                json.ItemOk();
            }
            json.totlalCount = vipUserService.GetVipUserCount();
            jsons = json.ToString();
            return jsons;
        }

下面是操作json的类:

/// <summary>
/// JSONHelper 的摘要说明
/// </summary>
public class JSONHelper
{
    //对应JSON的singleInfo成员
    public string singleInfo = string.Empty;
    protected string _error = string.Empty;
    protected bool _success = true;
    protected long _totalCount = 0;
    protected System.Collections.ArrayList arrData = new ArrayList();
    protected System.Collections.ArrayList arrDataItem = new ArrayList();


    public JSONHelper()
    {

    }

    //对应于JSON的success成员
    public bool success
    {
        get
        {
            return _success;
        }
        set
        {
            //如设置为true则清空error
            if (success) _error = string.Empty;
            _success = value;
        }
    }

    //对应于JSON的error成员
    public string error
    {
        get
        {
            return _error;
        }
        set
        {
            //如设置error,则自动设置success为false
            if (value != "") _success = false;
            _error = value;
        }
    }

    public long totlalCount
    {
        get { return _totalCount; }
        set { _totalCount = value; }
    }


    //重置,每次新生成一个json对象时必须执行该方法
    public void Reset()
    {
        _success = true;
        _error = string.Empty;
        singleInfo = string.Empty;
        arrData.Clear();
        arrDataItem.Clear();
    }

 

    public void AddItem(string name, string value)
    {
        arrData.Add("\"" + name + "\":" + "\"" + value + "\"");
    }

 

    public void ItemOk()
    {
        arrData.Add("<BR>");
        totlalCount++;
    }

    //序列化JSON对象,得到返回的JSON代码
    public override string ToString()
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("{");
        sb.Append("totalCount:" + totlalCount.ToString() + ",");
        sb.Append("success:" + _success.ToString().ToLower() + ",");
        sb.Append("error:\"" + _error.Replace("\"", "\\\"") + "\",");
        sb.Append("singleInfo:\"" + singleInfo.Replace("\"", "\\\"") + "\",");
        sb.Append("data:[");

        int index = 0;
        sb.Append("{");
        if (arrData.Count <= 0)
        {
            sb.Append("}]");
        }
        else
        {
            foreach (string val in arrData)
            {
                index++;

                if (val != "<BR>")
                {
                    sb.Append(val + ",");
                }
                else
                {
                    sb = sb.Replace(",", "", sb.Length - 1, 1);
                    sb.Append("},");
                    if (index < arrData.Count)
                    {
                        sb.Append("{");
                    }
                }

            }
            sb = sb.Replace(",", "", sb.Length - 1, 1);
            sb.Append("]");
        }

        sb.Append("}");
        return sb.ToString();
    }
}

再帮我看看吧

支持(0) 反对(0) 简小希 | 园豆:5 (初学一级) | 2011-11-10 16:18

@简小希: 光看代码很难查问题(因为我无法debug),你试试看data的数据条目不同的时候是不是一直少个大括号。

支持(0) 反对(0) 水牛刀刀 | 园豆:6350 (大侠五级) | 2011-11-10 16:20

@水牛刀刀: 您好,我刚刚测了一下,一条数据多条数据都是一样,少了一个大括号,本地都不会呀,怎么发布服务器就那样了呢,我重新发布了四次了,还是少了一个大括号,还有什么原因呢?

支持(0) 反对(0) 简小希 | 园豆:5 (初学一级) | 2011-11-10 16:26

@简小希: 你把你代码中可能修改json的地方都列出来,不要只贴代码,代码没法看。

支持(0) 反对(0) 水牛刀刀 | 园豆:6350 (大侠五级) | 2011-11-10 17:31

@水牛刀刀: 您好,除了那个生成json的方法,每次最终用这个 Response.Write(那个字符串json)来输出, Response.Flush();Response.Close();这两个在Response.Write()后执行,会不会是这个Response.Write()的原因呢?我是在.aspx.cs文件输出的,不是.ashx文件,有关系吗?

还有,比如在UI插入一条数据,后台成功后,我是这样输出的:Response.Write("{success:true,msg:'添加成功'}");Response.Flush();Response.Close();这样就没有调用那个生成json的方法了,可最后那个大括号还是没输出呀?

支持(0) 反对(0) 简小希 | 园豆:5 (初学一级) | 2011-11-11 17:51

@简小希: 你的意思是输出的是这样?

 {success:true,msg:'添加成功'
支持(0) 反对(0) 水牛刀刀 | 园豆:6350 (大侠五级) | 2011-11-11 18:09

@水牛刀刀: 对,就是这样

支持(0) 反对(0) 简小希 | 园豆:5 (初学一级) | 2011-11-12 09:03

@简小希: 你是在哪里看到返回的数据少了大括号的?是用的浏览器(或者其他嗅探工具如fiddler)捕获到的响应数据,还是你自己在js里用代码输出的?如果是前一种,那我真的没办法了。如果是后一种,再查查你js里有没有操作过json。

支持(0) 反对(0) 水牛刀刀 | 园豆:6350 (大侠五级) | 2011-11-12 10:44

@水牛刀刀: 用firebug查看的响应数据,哎,看来是解决不了。。。

支持(0) 反对(0) 简小希 | 园豆:5 (初学一级) | 2011-11-12 11:08
0

如果确定有数据,就要检查UI层,特别是JS ,路径是否正确,引用的文件是否是在站点目录下

蓝蓝的天 | 园豆:50 (初学一级) | 2011-11-09 16:50

您好,我刚刚用firebug看了一下,页面上全部引用的js都访问成功,访问状态都是200 ok,会不会买的空间不支持extjs呢?但是UI可以显示出来呀,extjs跨语言平台应该不用设置什么吧,这是服务器响应的数据:{totalCount:2,success:true,error:"",singleInfo:"",data:[{"id":"18","product_ID":"12","Name":"12","Price":"12.0000","salePrice":"12.0000","Discount":"1","Size":"0","Diameter":"12","Weight":"12","Picture":"2.gif","took":"","desc":"112","stockCount":"0","series":"12","categoty":"12","create_date":"2011-11-08","create_by":"admin","update_date":"2011-11-08","update_by":"admin","status":"0","kill_time":"2011-11-8 18:12:05","kill_count":"0","isKill":"0","Material":"12","purity":"12"},{"id":"17","product_ID":"12","Name":"12","Price":"12.0000","salePrice":"12.0000","Discount":"1","Size":"0","Diameter":"12","Weight":"12","Picture":"01x.jpg","took":"01.png","desc":"12","stockCount":"0","series":"12","categoty":"12","create_date":"2011-11-08","create_by":"admin","update_date":"2011-11-08","update_by":"admin","status":"1","kill_time":"2011-11-8 18:09:53","kill_count":"0","isKill":"0","Material":"12","purity":"12"}],帮我看看吧?

支持(0) 反对(0) 简小希 | 园豆:5 (初学一级) | 2011-11-10 11:29
0

看看客户端是不是取到数据了。

LCM | 园豆:6876 (大侠五级) | 2011-11-09 17:11

嗯,数据取到了,这是服务器响应的数据:{totalCount:2,success:true,error:"",singleInfo:"",data:[{"id":"18","product_ID":"12","Name":"12","Price":"12.0000","salePrice":"12.0000","Discount":"1","Size":"0","Diameter":"12","Weight":"12","Picture":"2.gif","took":"","desc":"112","stockCount":"0","series":"12","categoty":"12","create_date":"2011-11-08","create_by":"admin","update_date":"2011-11-08","update_by":"admin","status":"0","kill_time":"2011-11-8 18:12:05","kill_count":"0","isKill":"0","Material":"12","purity":"12"},{"id":"17","product_ID":"12","Name":"12","Price":"12.0000","salePrice":"12.0000","Discount":"1","Size":"0","Diameter":"12","Weight":"12","Picture":"01x.jpg","took":"01.png","desc":"12","stockCount":"0","series":"12","categoty":"12","create_date":"2011-11-08","create_by":"admin","update_date":"2011-11-08","update_by":"admin","status":"1","kill_time":"2011-11-8 18:09:53","kill_count":"0","isKill":"0","Material":"12","purity":"12"}],

支持(0) 反对(0) 简小希 | 园豆:5 (初学一级) | 2011-11-10 11:30

@简小希: 你发上来的代码没法看,估计也不会有什么错误,你可以从运行的环境找找原因,比如本机的IIS和服务器的IIS版本一样吗?装的framework版本都一样吗?你测试的浏览器版本都一样吗?

支持(0) 反对(0) LCM | 园豆:6876 (大侠五级) | 2011-11-11 08:50

@LCM: 我问了空间商,配置都满足我本地的,浏览器也一样,无缘无故少了一个大括号,重新发布了好几遍都没找到原因呢?

支持(0) 反对(0) 简小希 | 园豆:5 (初学一级) | 2011-11-11 17:34
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册