Reputation: 15898
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.
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. With the getRequest method I initialize my service "workaround" with which my jsonreststore can handle the authorization.
In firebug (Chrome) I get the following errors:
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.
Upvotes: 0
Views: 857
Reputation: 6828
You don't need to use 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();
});
Upvotes: 2