# Other Languages > jQuery >  Confused about code to DOWNLOAD - want to modify to pass large JSON to download page

## szlamany

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...



```
$.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



```
        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.



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

What is that supposed to be doing???

----------


## szlamany

I found a link online that indicated that if the .load is called with a function then that function is run when the element has been loaded.

http://www.w3schools.com/jquery/event_load.asp

With a frame that is doing a download - when is the frame loaded?  When the download is started or completed??

----------


## tr333

Why go to a third-rate source when you can go to the real thing?  :Stick Out Tongue: 

I think you're getting confused here between binding to the load event (which is deprecated) and load() which fetches data from a remote location and places the returned HTML into the matched elements.  In this case, the parameter to load() will be a function that returns the URL to use for fetching data.  It will run as soon as .load() is called, unless you have chained some .delay() into it.

----------

