﻿$.download = function (url, data, method, callback) {
    var inputs = '';
    var iframeX;
    var downloadInterval;
    if (url && data) {
        // remove old iframe if has 
        if ($("#iframeX")) $("#iframeX").remove();
        // creater new iframe 
        iframeX = $('<iframe name="iframeX" id="iframeX"></iframe>').appendTo('body').hide();

        //split params into form inputs 
        $.each(data, function (p, val) {
            inputs += '<input type="hidden" name="' + val.name + '" value="' + val.value + '" />';
        });

        //create form to send request 
        $('<form action="' + url + '" method="' + (method || 'post') + '" target="iframeX">' + inputs + '</form>').appendTo('body').submit().remove();
    };
};
