jQuery Ajax: pdf response jQuery Ajax: pdf response ajax ajax

jQuery Ajax: pdf response


Be sure your server side returns a downloadeable content and make a submit to the file, something like:

            //$.download('path', 'data' [, 'post'])            $.download = function(url, data, method) {                //url and data options required                if(url && data) {                    var form = $('<form />', { action: url, method: (method || 'get') });                    $.each(data, function(key, value) {                        var input = $('<input />', {                            type: 'hidden',                            name: key,                            value: value                        }).appendTo(form);                    });                return form.appendTo('body').submit().remove();                }            throw new Error('$.download(url, data) - url or data invalid');            };$.download("index.php?route=sale/order/superfaktura_getpdf&token=<?php echo $token; ?>", {}, 'post')


It won't work because AJAX calls do NOT fetch PDF and load it inside the browser. That's why it's called XMLHttpRequest.. it only exchanges just text!