The Dojo is a JavaScript toolkit(library) that provides many utility modules and functions to create a web application. We can save time and speed up the development process using the predefined Dojo modules. Dojo includes language utilities, UI components, and more. Read more about Dojo at their homepage.
dojo/request
?Using dojo/request
API, we can make
How to use the dojo/request
:
dojo/request
module using the require
function.get
or post
method to make a request. Let's make sample GET
and POST
requests using the dojo/request
.
In the above code snippet:
loadDojo
. This function will use the require
function to load the dojo/request
module. Once that module is loaded we assign the request object to a variable. So that we can use that to send AJAX requests.sendGetRequest
. Inside this method we define successCallback
and errorCallback
function. Invoke the get method of the DojoRequest
object with URL
, successCallback
and errorCallback
as arguments. Once the request succeeds the successCallback
function will be invoked. If the request fails the errorCallback
function will be invoked.sendPostRequest
. Inside this method, we defined options for the POST
request. In the options, we provided the data that is to be sent along with the request and headers for the request. Also, we created successCallback
and errorCallback
functions. Invoke the post
method of the DojoRequest
object with (URL,options
), successCallback
and errorCallback
as arguments. Once the post request succeeds the successCallback
function will be invoked. If the request fails the errorCallback
function will be invoked.Free Resources