.net平台与EXTJS数据交互问题 。net平台或者JAVA ,PHP在与EXTJS交互数据时,用JSON数据格式都有不同的处理方法,但.NET是如何返回JSON格式的数据呢,我尝试好多次都未成功。都会返回多余的前辍。是不是在EXTJS请求时,请求的页面不是.ASPX扩展名的文件? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 原理都是一样的我们公司里以前用的最多是HttpHandler返回JSON格式 有例子不,求一个好应用例子,做MVC研究。 没整理返回格式{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 給你的思路:整合Js+C#的调用,我以前也是用了很多的HttpHandler但是现在就用一个HttpHandler的类就OK了。原理:在HttpHandler中反射,参数是从HttpHandler上下文的Form中取得,然后动态转换数据。方法反射调用结束后统一转换为Json json是个标准的数据交换格式,对任何的语言都是通用的。 <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文件上的代码 参考一下吧 用过EXTJS这个JS框架的话,前台就用一个静态页面index.html在这个静态页面里边加载JS代码,当然现在EXTJS框架可以动态加载JS文件。 使用EXTJS框架,整个项目就只使用一个html文件就可以了。 GetTreeJson 方法里边的字符串连接 用 System.Text.StringBuilder 替换一下比较好。。 求此验证码识别方法 非静态的字段、方法或属性“System.Web.UI.Page.Session.get”要求对象引用 未能加载文件或程序集"*"的错误怎么办? 2.0和1.1共存的服务器,1.1开发的东西用2.0后变成乱码,救命吧 静态函数占用服务器内存吗 求测试文档 gridview数据源问题 斑竹,细心的朋友能否给我这个网址? asp里面能捕捉到ActiveX控件的事件吗? 看来.NET还是识别大小写的哦!那不是好麻烦! 我想做个注册页面,后台数据库为SQL,但是做完后执行没反应。。求助大大 .net中,在做动态网页时,母板页与内容页如何同步?求教!
我们公司里以前用的最多是HttpHandler
返回JSON格式
返回格式{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
整合Js+C#的调用,我以前也是用了很多的HttpHandler
但是现在就用一个HttpHandler的类就OK了。
原理:在HttpHandler中反射,参数是从HttpHandler上下文的Form中取得,然后动态转换数据。
方法反射调用结束后统一转换为Json
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文件上的代码 参考一下吧
GetTreeJson 方法里边的字符串连接 用 System.Text.StringBuilder 替换一下比较好。。