djanix
6/12/2014 - 2:07 PM

jquery ajax call

jquery ajax call

function loadItems(url, params, callback) {
    $.ajax({
        url: url,
        dataType: 'json',
        contentType: 'application/json',
        data: JSON.stringify(params),
        type: 'POST'
    })
    .done(function (data, textStatus, jqXHR) {
        var result = ((typeof data) == "string") ? $.parseJSON(data) : data;
        return callback(null, result);
    })
    .fail(function (jqXHR, textStatus, errorThrown) {
        return callback(['fail', errorThrown], null);
    });
}