[英]binding dojo.grid to restful service with authentication via jsonreststore
I searched a while for this issue, but could not find much about it. 我搜索了一下这个问题,但找不到多少。
In my javascript application I try to visualize data of my restful backend via jsonreststore and dgrid. 在我的javascript应用程序中,我尝试通过jsonreststore和dgrid可视化我的restful后端的数据。
That is what I got so far: 这就是我到目前为止所得到的:
<script>
function getRequest(args) {
return {
url: 'http://myworkingapiwithevents/events',
handleAs: 'json',
sync: false,
headers: {
'Authorization': 'Basic HriB5jsHUib2K='
}
}
}
require(["dojo/store/JsonRest", "dojo/rpc/JsonService"], function (JsonRest, JsonService) {
service = new JsonService('http://myworkingapiwithevents/events', true /*isJson*/, undefined /*schema*/, getRequest);
myStore = new JsonRest({ service: service });
});
require(["dojox/grid/DataGrid", "dojo/data/ObjectStore", "dojo/domReady!"
], function (DataGrid, ObjectStore) {
grid = new DataGrid({
store: dataStore = new ObjectStore({ objectStore: myStore }),
structure: [
{ name: "Event", field: "name", width: "200px" }
]
}, "grid3");
grid.startup();
});
</script>
For the beginning I use a hardcoded base64 authorization which should work for my backend service. 首先,我使用硬编码的base64授权,该授权适用于我的后端服务。 With the getRequest method I initialize my service "workaround" with which my jsonreststore can handle the authorization.
使用getRequest方法,我初始化我的服务“变通方法”,我的jsonreststore可以使用它来处理授权。
In firebug (Chrome) I get the following errors: 在firebug(Chrome)中,我收到以下错误:
ErrorCtor {stack: "Error: Unable to load http://myworkingapiwithevents/ev... p://localhost:52894/Scripts/dojo/dojo.js:1094:43)", message: "Unable to load http://myworkingapiwithevents/events status: 0", response: Object, status: 0, responseText: ""…}
Error {popStackFrame: function} "Error: Unable to load SMD from http://myworkingapiwithevents/events
Could it be some cross domain issue? 可能是一些跨域问题? I know that my backendservice supports cross domain.
我知道我的后端服务支持跨域。
You don't need to use dojo/rpc/JsonService. 您不需要使用dojo / rpc / JsonService。 Try this instead :
试试这个:
require(["dojo/store/JsonRest", "dojox/grid/DataGrid", "dojo/data/ObjectStore", "dojo/domReady!"], function (JsonRest, DataGrid, ObjectStore) {
var restStore = new JsonRest({
target : 'http://myworkingapiwithevents/events',
headers: {'Authorization': 'Basic HriB5jsHUib2K='}
});
var dataStore = new ObjectStore({ objectStore : restStore });
grid = new DataGrid({
store: dataStore,
structure: [
{ name: "Event", field: "name", width: "200px" }
]
}, "grid3");
grid.startup();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.