Skip to Content

Ajax requests

About

Breeze provides a wrapper around fetch function to make requests in jQuery-like API.

View Source Code

Sending request

$.ajax(url|options);
$.ajax(url|options, data|successFn);
$.get(url|options, data|successFn);
$.post(url|options, data|successFn);

Options

Here is a list of available options:

$.ajax({
    url: 'url',
    method: 'get|post|put|delete|head',
    headers: {
        'X-Requested-With': 'XMLHttpRequest'
    },
    data: Object|$('#myform'),
    success: (data, response) => {},
    complete: (response) => {},
    error: (response, error) => {},
});

You can pass other options that are the part of fetch API.

Aborting request

Ajax function returns a Promise with custom abort method. Use it to abort unfinished request:

var promise = $.get({
    url: 'url',
    error: function (response, error) {
        // response is undefined when request is aborted
        console.log(error);
    }
});

promise.abort();