我正在尝试使用 extjs 存储与返回 Json 的 Jersey REST Java 应用程序(在 tomcat 上运行)对话。我正在尝试使用 Json 打印到网格组件。这是我的商店代码。
Ext.define('WSC.store.Users', {
extend: 'Ext.data.Store',
fields: ['period','tot_units', 'tot_selling_price'],
model: 'WSC.model.User',
proxy: {
type: 'rest',
url : 'http://localhost:8080/mondrianCube/services/query/querygoeshere/json',
reader: {
type: 'json',
root: 'table'
}
},
autoLoad: true
});
商店无法读取获得的 json。大多数建议是将响应标头(Access-Control-Allow-Origin)添加到 webapp(在 tomcat 上运行)。所以我添加了如下的响应头。
@Path("/query/{qryParam}/json")
@GET
@Produces(MediaType.APPLICATION_JSON)
public static Response jsonResult(@PathParam("qryParam") String qryParam) throws JSONException
{
executeQuery("select {[Measures].members} on columns, {Time.[2010], Time.[2010]} on rows from sales" );
String json = (new JSONObject(((new ResultSetConvert(result)).toJson()))).toString();
return Response.ok(json).header("Access-Control-Allow-Origin","*").build();
}
即使那样我也得到与下面相同的错误
我在这里想念什么?
PS 如果 url 指向同域中的文件,则 store 能够读取文件中的 json。