M
M
Msim2015-11-18 00:50:58
PHP
Msim, 2015-11-18 00:50:58

How to download csv file via ajax?

It is necessary to insert the file into the input file and process and send headers for the csv download to the return line. At the last point, it simply ignores the headers and does nothing as soon as you remove ajax, then everything works with a bang. How to organize to let ajax know that you need to download a file.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2015-11-18
@Msim

if I understand you correctly then

$("#target-file").bind("change", function (event) {
    var formData = new FormData($('#file-form')[0]);
    $.ajax({
            type: 'POST',
            url: '/file/processingFile',
            dataType: 'json',
            enctype: 'multipart/form-data',
            data: formData,
            contentType: false,
            processData: false,
            cache: false,
            'success': function (data) {
               
            }, 'error': function (request) {
                
            }}
    );
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question