Results 1 to 3 of 3

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

  1. #1

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

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

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

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  2. #2

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Confused about code to DOWNLOAD - want to modify to pass large JSON to download p

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

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  3. #3
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    Re: Confused about code to DOWNLOAD - want to modify to pass large JSON to download p

    Why go to a third-rate source when you can go to the real thing?

    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.
    Last edited by tr333; Dec 24th, 2012 at 06:11 PM.
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width