前台代码:
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");