Ext.data.ScriptTagProxy是解决跨域访问的
在服务器端需要做一些处理,而不是单纯的返回json字符串
下边是EXT的API文档中提供的示例,这段后台代码会自动判断请求的类型,返回支持ScriptTagProxy或HttpProxy的数据
jsonObject是通过json.jar创建的json对象。
在服务器端需要做一些处理,而不是单纯的返回json字符串
下边是EXT的API文档中提供的示例,这段后台代码会自动判断请求的类型,返回支持ScriptTagProxy或HttpProxy的数据
PrintWriter out = response.getWriter();
boolean scriptTag = false;
String cb = request.getParameter("callback");
if (cb != null) {
scriptTag = true;
response.setContentType("text/javascript");
} else {
response.setContentType("application/x-json");
}
if (scriptTag) {
out.write(cb + "(");
}
out.print(jsonObject.toString());
if (scriptTag) {
out.write(");");
}
jsonObject是通过json.jar创建的json对象。