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.
The second way is the "best" one; Dojo is modeled on the Store interface for retrieving and manipulating (server-side) data. The other ways may not be wrong, but are not the "Dojo way" of using a REST interface.
The target parameter should contain the rest endpoint (/service/getquestions/projectId). When you want to retrieve information for a specific project, you would call store.get(projectId) on the store which would then perform a GET request to /service/getquestions/projectId/projectid and return the appropriate data.
In the same way an update can be done by calling store.put(object), which will do a PUT request on /service/getquestions/projectId/projectid.
Hope this helps. If not, more information on stores can be found here.