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 or json. 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 or json. 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:

    1. var app = new Framework7();
    2. var $$ = Dom7;
    3. app.request.post('auth.php', { username:'foo', password: 'bar' }, function (data) {
    4. $$('.login').html(data);
    5. 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 or json. By default is json. 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:

    1. var app = new Framework7();
    2. var $$ = Dom7;
    3. app.request.postJSON('http://api.myapp.com', { username:'foo', password: 'bar' }, function (data) {
    4. console.log(data);
    5. });

    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.requestParametersObject with passed XHR request parameters
    xhr.requestUrlString with request URL