。net平台或者JAVA ,PHP在与EXTJS交互数据时,用JSON数据格式都有不同的处理方法,但.NET是如何返回JSON格式的数据呢,我尝试好多次都未成功。都会返回多余的前辍。是不是在EXTJS请求时,请求的页面不是.ASPX扩展名的文件?

解决方案 »

  1.   

    原理都是一样的
    我们公司里以前用的最多是HttpHandler
    返回JSON格式
      

  2.   

    有例子不,求一个好应用例子,做MVC研究。
      

  3.   

    没整理
    返回格式{success:true/false, data:返回信息}
    ExtJS是异步的
    success返回true,在success:function(){处理执行成功}
    success返回false,在failure:function(){处理执行失败}这里的参数ajax和formpanel提交有点不同,注意区分
    ajax success:failure(resp, opts){}
    resp是返回的json格式,文字的要decode一下,opts是请求的参数,不用管form表单提交返回
    success:function(form, action){}
    form是表单的BasicForm, action.result是返回的JSON格式,不用decode
      

  4.   

    給你的思路:
    整合Js+C#的调用,我以前也是用了很多的HttpHandler
    但是现在就用一个HttpHandler的类就OK了。
    原理:在HttpHandler中反射,参数是从HttpHandler上下文的Form中取得,然后动态转换数据。
    方法反射调用结束后统一转换为Json
      

  5.   

    json是个标准的数据交换格式,对任何的语言都是通用的。
      

  6.   

     <script type="text/javascript">
            Ext.onReady(function () {
                var tree = new Ext.tree.ColumnTree({
                    el: 'tree-ct',
                    width: 750,
                    autoHeight: true,
                    rootVisible: false,
                    autoScroll: true,
                    title: 'Redmine',                columns: [{
                        header: '项目',
                        width: 350,
                        dataIndex: 'task'
                    }, {
                        header: '小项目',
                        width: 100,
                        dataIndex: 'duration'
                    }, {
                        header: '问题',
                        width: 100,
                        dataIndex: 'user'
                    },
                    {
                        header: '小问题',
                        width: 100,
                        dataindex: '_Problem'
                    }],
                    loader: new Ext.tree.TreeLoader({
                        dataUrl: 'Service_comlumnTree.aspx?cmd=tree',
                        listeners: {
                            load: function () {
                                this;
                            }
                        },
                        uiProviders: {
                            'col': Ext.tree.ColumnNodeUI
                        }
                    }),                root: new Ext.tree.AsyncTreeNode({
                        text: 'Tasks'
                    })
                });
                tree.render();
            });
        </script>这是我卸载HTML页面上的前台代码  红色部分是我连接数据库的部分
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;public partial class Service_comlumnTree : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string cmd = Request.QueryString["cmd"];
            switch (cmd)
            {
                case "tree":
                    GetTreeJson();
                    break;
                default:
                    break;
            }
        }
        public void GetTreeJson()
        {
            string json = "[{";
            json += "task:'ColumnTree Example',";
            json += "duration:'3 hours',";
            json += "user:'',";
            json += "uiProvider:'col',";
            json += "cls:'master-task',";
            json += "iconCls:'task-folder',";        json += "'children':[{";
            json += "task:'Abstract rendering in TreeNodeUI',";
            json += "duration:'15 min',";
            json += "user:'Jack Slocum',";
            json += "uiProvider:'col',";
            json += "cls:'master-task',";
            json += "iconCls:'task-folder',";        json += "children:[{";
            json += "task:'Abstract rendering in TreeNodeUI',";
            json += "duration:'15 min',";
            json += "user:'Jack Slocum',";
            json += "uiProvider:'col',";
            json += "cls:'master-task',";
            json += "iconCls:'task-folder'";
            json += "},{";        json += "children:[{";
            json += "task:'Create TreeNodeUI with column knowledge',";
            json += "duration:'45 min',";
            json += "user:'Jack Slocum',";
            json += "uiProvider:'col',";
            json += "leaf:true,";
            json += "iconCls:'task'";
            json += "},{";        json += "task:'Create TreePanel to render and lock headers',";
            json += "duration:'30 min',";
            json += "user:'Jack Slocum',";
            json += "uiProvider:'col',";
            json += "leaf:true,";
            json += "iconCls:'task'";
            json += "},{";        json += "task:'Add CSS to make it look fly',";
            json += "duration:'30 min',";
            json += "user:'Jack Slocum',";
            json += "uiProvider:'col',";
            json += "leaf:true,";
            json += "iconCls:'task'";
            json += "},{";        json += "}]";
            json += "}]";
            json += "}]";
            json += "}]";
            Response.Write(json);
            Response.End();
        }
    }只是我写在Service_comlumnTree.aspx.cs文件上的代码  参考一下吧
      

  7.   

    用过EXTJS这个JS框架的话,前台就用一个静态页面index.html在这个静态页面里边加载JS代码,当然现在EXTJS框架可以动态加载JS文件。
      

  8.   

    使用EXTJS框架,整个项目就只使用一个html文件就可以了。
      

  9.   


    GetTreeJson 方法里边的字符串连接 用 System.Text.StringBuilder 替换一下比较好。。