export default function ajax(option) {
    var action = option.action, file = option.file, filename = option.filename, method = option.method, onProgress = option.onProgress, onSuccess = option.onSuccess, onError = option.onError, headers = option.headers, withCredentials = option.withCredentials, data = option.data;
    var xhr = new XMLHttpRequest();
    xhr.open(method, action, true);
    xhr.onerror = onError;
    xhr.onload = onSuccess;
    if (xhr.upload) {
        xhr.upload.onprogress = function progress(e) {
            if (e.total > 0) {
                var percent = (e.loaded / e.total) * 100;
                onProgress(percent);
            }
        };
    }
    if (withCredentials && 'withCredentials' in xhr) {
        xhr.withCredentials = true;
    }
    var formData = new FormData();
    formData.append(filename, file);
    if (data) {
        Object.keys(data).forEach(function (key) {
            formData.append(key, data[key]);
        });
    }
    if (headers) {
        for (var item in headers) {
            if (headers[item]) {
                xhr.setRequestHeader(item, headers[item]);
            }
        }
    }
    xhr.send(formData);
    return xhr;
}
//# sourceMappingURL=ajax.js.map