如何使用DOJO从服务器读取JSON响应?
How can I read a JSON reponse from server using DOJO?
我有一些麻烦从服务器获取一些数据,并用它填充数据存储:
这是我在Display.jsp页面中的脚本代码:dojo.require("dojox.grid.DataGrid");
dojo.require("dojo.data.ItemFileReadStore");
dojo.addOnLoad(function() {
// our test data store for this example:
dojo.xhrGet({
url: "jsonAction.action",// this line can call the action in struts2. I had tested it !
handleAs: "json",
preventCache: true,
load: function(response, ioArgs){
//dojo.byId("replace").innerHTML = response;
// I can get json data by changing handleAs:"text"
//return response; //
}
});
var jsonStore = new dojo.data.ItemFileReadStore({
//??? how can I get the json data?
});
我想稍后使用这些数据来填充dojox.grid.DataGrid
我正在使用Struts2, Hibernate, Tomcat 6
不使用dojo.xhrGet
。dojo.data.ItemFileReadStore
有一个参数url
,可以指定数据源。下面是一个网格示例:
var sampleGrid = new dojox.grid.DataGrid({
store: new dojo.data.ItemFileReadStore({
url: "JSON_source",
clearOnClose: true,
urlPreventCache: true
}),
structure: [
{cells:
[[
{field: "JSON_field", name: "displayed value"},
...
]]
}
],
...
});
相关文章:
- 在不同的javascript数组中对json响应进行排序
- Laravel数据表无效的JSON响应
- 使用Backbone.js访问JSON响应的部分
- 不需要的JSON响应
- 跨多个域的json响应
- 将对Ajax PUT的json响应重定向到要由EL解析的JSP中
- handler没有为JSON响应正确填充模板
- 如何在phonegap应用程序中处理Ajax json响应
- 将JSON响应放入var中并输出
- 如何使用AngularJS将if语句conditon与json响应一起使用
- JS-通用解析JSON响应
- 将json响应格式化为父级和子级
- 从 JSON 响应解析数据
- 单个和多个 JSON 响应
- 将日期作为从 Web API 到 angularJS 的 json 响应
- 在 JSX Render for React.js 中遍历 JSON 响应
- 使用 JavaScript 从 URL 获取 JSON 响应
- 使用来自AngularJS的Web API JSON响应-错误:应为和数组,但得到了一个对象
- 生成动态json响应的Javascript
- 如何将json响应的一部分转换为map