js代码:
store : Ext.create('Ext.data.Store',{
model : 'portal.model.OperationModel',
proxy: {
type: 'jsonp',// 使用jsonp
url : 'http://192.168.1.38:8080/oorp/getRecentlyAddResource',//远程url
reader: {
type: 'json',
root: 'data'
}
}
}),
store.load();
后台java代码:
JSONArray ja = desktopService.getRecentlyAddResource(user);
// success(ja);
// 回调方法,默认是callback,可以在proxy中通过callbackKey设置
String cb = request.getParameter("callback");
JSONObject result = new JSONObject();
result.put("success", true);
result.put("data", ja);
response.setContentType("text/javascript");
OutputStreamWriter out =
new OutputStreamWriter(response.getOutputStream(), "utf-8");
String str = cb + "(" + result.toString() + ");";
out.write(str);
out.flush();
out.close();
其他语言类似,需要返回格式为:
callback({“data”:[{“id”:”my id”}],”success”:true})