Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42359

Confused about code to DOWNLOAD - want to modify to pass large JSON to download page

$
0
0
I have been using this function I found a long time ago to do downloads - I want to modify it to pass a large JSON string to the download.aspx page. With that said I am trying to first understand it and I am confused...

Code:

$.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 src="[removed]false;" name="iframeX" id="iframeX"></iframe>').appendTo('body').hide();
        if($.browser.msie){
            downloadInterval = setInterval(function(){
                // if loading then readyState is “loading” else readyState is “interactive”
                if(iframeX&& iframeX[0].readyState !=="loading"){
                    callback();
                    clearInterval(downloadInterval);
                }
            }, 23);
        } else {
            iframeX.load(function(){
                callback();
            });
        }
        //split params into form inputs
        var inputs = '';
        jQuery.each(data.split('&'), function() {
            var pair = this.split('=');
            inputs += '<input type="hidden" name="' + pair[0] + '" value="' + pair[1] + '" />';
        });
        //create form to send request
        $('<form action="'+ url +'" method="'+ (method||'post') + '" target="iframeX">'+inputs+'</form>').appendTo('body').submit().remove();
    };
};

And I have been calling it like this

Code:

        function downloadrpt(rptid) {
            $.download('Download.aspx', 'rptid=' + rptid + '&user=' + window.username);
        }

        function downloadfile(filename) {
            $.download('Download.aspx', 'fn=' + filename + '&user=' + window.username);
        }

Note that I am only passing in two parameters to this function. That means that "callback" parameter is not defined within the function.

In that $.download function there is a iframeX.Load() call that I don't understand. I looked around and the jQuery .Load method doesn't seem to take a function as a parameter - and that callback() function is not even being passed in.

Code:

            iframeX.load(function(){
                callback();
            });

What is that supposed to be doing???

Viewing all articles
Browse latest Browse all 42359

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>