Request / Ajax
It is available as a property of Framework7 class (Framework7.request
) and same property on initialized app instance (app.request
):
app.request(parameters)- Load data from the server
- parameters - object - Request parameters
Returns plain XHR object
Framework7.request(parameters)- Load data from the server
- parameters - object - Request parameters
Returns plain XHR object
Let’s look at the list of available parameters
Request comes with some pre configured methods for ease of use.
app.request.get(url, data, success, error, dataType)- Load data from the server using a HTTP GET request
- url - string - Request url
- data - object - A plain object or string that is sent to the server with the request. Optional
- success - function (data, status, xhr) - A callback function that is executed if the request succeeds. Optional
- error - function (xhr, status) - A callback function that is executed if the request fails. Optional
- dataType - string - The type of data that you’re expecting back from the server. Could be
text
orjson
. Optional
Framework7.request.get(url, data, success, error, dataType)- Load data from the server using a HTTP GET request
Returns plain XHR object
For example:
app.request.post(url, data, success, error, dataType)- Load data from the server using a HTTP POST request
- url - string - Request url
- data - object - A plain object or FormData or string that is sent to the server with the request. Optional
- success - function (data, status, xhr) - A callback function that is executed if the request succeeds. Optional
- error - function (xhr, status) - A callback function that is executed if the request fails. Optional
- dataType - string - The type of data that you’re expecting back from the server. Could be
text
orjson
. Optional
Returns plain XHR object
Framework7.request.post(url, data, success, error, dataType)- Load data from the server using a HTTP POST request
Returns plain XHR object
For example:
var app = new Framework7();
var $$ = Dom7;
app.request.post('auth.php', { username:'foo', password: 'bar' }, function (data) {
$$('.login').html(data);
console.log('Load was performed');
app.request.json(url, data, success, error)- Load JSON-encoded data from the server using a GET HTTP request
- url - string - Request url
- data - object - A plain object or FormData or string that is sent to the server with the request. Optional
- success - function (data, status, xhr) - A callback function that is executed if the request succeeds. Optional
- error - function (xhr, status) - A callback function that is executed if the request fails. Optional
Method nothing returns
Method returns nothing
For example:
app.request.postJSON(url, data, success, error, dataType)- Send JSON data using a HTTP POST request
- url - string - Request url
- data - object - A plain object
- success - function (data, status, xhr) - A callback function that is executed if the request succeeds. Optional
- error - function (xhr, status) - A callback function that is executed if the request fails. Optional
- dataType - string - The type of data that you’re expecting back from the server. Could be
text
orjson
. By default isjson
. Optional
Returns plain XHR object
Framework7.request.postJSON(url, data, success, error, dataType)- Send JSON data using a HTTP POST request
Returns plain XHR object
For example:
var app = new Framework7();
var $$ = Dom7;
app.request.postJSON('http://api.myapp.com', { username:'foo', password: 'bar' }, function (data) {
console.log(data);
});
app.request.setup(parameters)- Set default values for future Ajax requests. Its use is not recommended
- parameters - object - Default requests parameters
Framework7.request.setup(parameters)- Set default values for future Ajax requests. Its use is not recommended
For example:
xhr.requestParameters | Object with passed XHR request parameters |
xhr.requestUrl | String with request URL |