-
Notifications
You must be signed in to change notification settings - Fork 3
Requests
Kwasi Yonkopa edited this page Aug 21, 2019
·
5 revisions
You can initiate an AJAX request easily by using the Dash.request() method
Syntax
Dash.request(url, data, success [, configuration]);Parameters
url: string
- URL to send request to
data: mixed
- A body of data to be sent in the XHR request, preferably FormData
success: Function
- A callback function to run after AJAX return
configuration: Object
- Configuation object containing options for making requests
These are the available options when configuring requests
{
// {String} The HTTP request method to use, such as "GET", "POST", "PUT", "DELETE", etc. Ignored for non-HTTP(S) URLs
method: 'POST',
// {Boolean} Is the request fetching a view/html
isViewRequest: false,
// {Array} Headers to add to request
headers: {},
// {Function} Callback called on progress
progress: null,
// {Function} Callback to handle errors
error: null,
// {Function} Callback to execute on successful request
success: null,
// {Boolean} Send PATCH requests as POST
usePost: false,
// {Boolean} Sets tempOffAutoReload to true
tempOffAutoReload: false,
// {Mixed} Form data to pass as request body
data: {}
}Example
var data = {
username: 'johndoe'
firstname: 'John',
lastname: 'Doe',
};
var success = function(response){
console.log(response)
};
Dash.request('https://app.com/api/v1/users', data, success, {
method: 'get',
error: function(){
console.log("Couldn't make request");
}
});You can use the following shortcut methods to create get and post requests.
Dash.get()
Dash.post()
Syntax
Dash.get(url, data, success, config);
Dash.post(url, data, success, config);Parameters
url: string
- URL to send request to
data: mixed
- A body of data to be sent in the XHR request, preferably FormData
success: Function
- A callback function to run after AJAX return
configuration: Object
- Configuation object containing options for making requests