I am new to Dojo Frame work, so please do bear with me. I have a service implemented in a way that it will return JSON response . I am using Dojo frame work for UI. I am not sure about the right way to request to server and get the response in dojo.
I found 3 ways to request to server and receiving response.am not sure whether it's wrong or even remotely right
1)
request(contextName+"/service/getquestions/projectId/"+projectId,{
handleAs: "json"
}).then(function(data){alert("something")});
2)
var questionAnswerStore = new JsonRest({
target: contextName+"/service/getquestions/projectId/"+projectId,
});
3)
request.get("contextName+"/service/getquestions/projectId/"+projectId",{
handleAs: "json"
}).then(function(data){
dataStore = new ObjectStore({ objectStore:new Memory({ data: data.items }) });
});
Further, the store created will be used to populate the dgrid elements. Any help is appreciated.
When working with widgets you should wrap your data in a
dojo/store
. That leaves out your first method.The second one, like @PaulR told you, is the best approach. But it also means your REST service should follow certain rules which you can find at their reference guide. If you cannot meet these standards, you can choose to extend the
dojo/store/JsonRest
module so you can make it conform or you use the third method.The third method is probably the easiest if your REST service is not compliant with the requirements. You do not need to use the
dojo/data/ObjectStore
adapter in the new versions of Dojo, since all widget stores should be using thedojo/store
API now (and not the olddojo/data
API).