Ext在和后端通信使用Json时,要使用"callback('Json');"这种形式,原因是[quote]grid提交分页数据的时候后面还会自动跟随一个可以说是标识的字段callback=stcCallback1001
每提交一次请求,callback就会自增,也就是说第二次就是callback=stcCallback1002
对应的,你的php文件回传json数据的时候也要带上这个值,来确定是哪次的请求所返回的结果
格式是:
stcCallback1001(
{ ‘results’: 2, ‘rows’: [
{ ‘id’: 1, ‘name’: ‘Bill’, occupation: ‘Gardener’ },
{ ‘id’: 2, ‘name’: ‘Ben’, occupation: ‘Horticulturalist’ } ]
}
);
他每次提交的数据是附加在网址后面的格式是
?start=0&limit=25&_dc=1185695314632&callback=stcCallback1001
statr:起始数据值
limit:每页数据条数
_dc:自动生成的时间戳
callback:回传的确认值
要注意的是JSON-CODE中要严格按照其格式定义:{"totalProperty:".总行数,“ROOT:".JSON_ENCODE($DATA)}
另外,在ext-js中,使用JsonReader声明所读的数据是日期时,也要注意,要不就不要声明,要声明就得确定jsondata中的日期格式与你声明的一致。
出自:[url]http://www.centuryidea.cn/index.php?tag=php[/url]
[/quote]
所以对应的服务器端的实现:[code]
String callback=request.getParameter("callback");
String json = callback+"({totalProperty:100,root:[";
json += "{col1:" + 1 + ",col2:'name" + i + "',col3:'descn" + 1 + "'}";
json += "]});";
回传的结果类似于:
stcCallback1001({totalProperty:100,root:[{col1:1,col2:'name1',col3:'descn1'}]});[/code]
在创建Ext.data.Store对象时,proxy属性使用Ext.data.ScriptTagProxy,不要使用Ext.data.HttpProxy。
[quote]
Ext API
Class Ext.data.HttpProxy
Note that this class cannot be used to retrieve data from a domain other than the domain from which the running page was served.
Class Ext.data.ScriptTagProxy
Note that if you are retrieving data from a page that is in a domain that is NOT the same as the originating domain of the running page, you must use this class, rather than HttpProxy.
[/quote]
很奇怪,使用这种形式proxy: new Ext.data.ScriptTagProxy({url:'PagingGrid.jsp'})可以正常显示,但proxy: new Ext.data.HttpProxy({url:'PagingGrid.jsp'})这种就不行(我理解错了?)。
每提交一次请求,callback就会自增,也就是说第二次就是callback=stcCallback1002
对应的,你的php文件回传json数据的时候也要带上这个值,来确定是哪次的请求所返回的结果
格式是:
stcCallback1001(
{ ‘results’: 2, ‘rows’: [
{ ‘id’: 1, ‘name’: ‘Bill’, occupation: ‘Gardener’ },
{ ‘id’: 2, ‘name’: ‘Ben’, occupation: ‘Horticulturalist’ } ]
}
);
他每次提交的数据是附加在网址后面的格式是
?start=0&limit=25&_dc=1185695314632&callback=stcCallback1001
statr:起始数据值
limit:每页数据条数
_dc:自动生成的时间戳
callback:回传的确认值
要注意的是JSON-CODE中要严格按照其格式定义:{"totalProperty:".总行数,“ROOT:".JSON_ENCODE($DATA)}
另外,在ext-js中,使用JsonReader声明所读的数据是日期时,也要注意,要不就不要声明,要声明就得确定jsondata中的日期格式与你声明的一致。
出自:[url]http://www.centuryidea.cn/index.php?tag=php[/url]
[/quote]
所以对应的服务器端的实现:[code]
String callback=request.getParameter("callback");
String json = callback+"({totalProperty:100,root:[";
json += "{col1:" + 1 + ",col2:'name" + i + "',col3:'descn" + 1 + "'}";
json += "]});";
回传的结果类似于:
stcCallback1001({totalProperty:100,root:[{col1:1,col2:'name1',col3:'descn1'}]});[/code]
在创建Ext.data.Store对象时,proxy属性使用Ext.data.ScriptTagProxy,不要使用Ext.data.HttpProxy。
[quote]
Ext API
Class Ext.data.HttpProxy
Note that this class cannot be used to retrieve data from a domain other than the domain from which the running page was served.
Class Ext.data.ScriptTagProxy
Note that if you are retrieving data from a page that is in a domain that is NOT the same as the originating domain of the running page, you must use this class, rather than HttpProxy.
[/quote]
很奇怪,使用这种形式proxy: new Ext.data.ScriptTagProxy({url:'PagingGrid.jsp'})可以正常显示,但proxy: new Ext.data.HttpProxy({url:'PagingGrid.jsp'})这种就不行(我理解错了?)。
3976

被折叠的 条评论
为什么被折叠?



