# Other Languages > jQuery >  jQuery Ajax to download a file

## szlamany

Has anyone downloaded files with a jQuery ajax call - to a web service would be ideal...

We fooled with MS Ajax Downloader stuff months ago - didn't like it and can't recall why.

Also did jDownload testing months ago - but that seems to be defunct now.

Anyone doing anything like this?

I want to download PDF files using ajax.

----------


## szlamany

I found this code - and don't understand it much - but it's calling my download.aspx page



```
$.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 
        $.each(data, function(p, val){ 
            inputs+='<input type="hidden" name="'+ p +'" value="'+ val +'" />';
        });
        //create form to send request 
        $('<form action="'+ url +'" method="'+ (method||'post') + '" target="iframeX">'+inputs+'</form>').appendTo('body').submit().remove();
    };
};
```

I tried calling it like this - but the filename isn't passing in.



```
$.download('Download.aspx', 'filename=mitlicense.txt');
```

Can someone help explain to me the iframe and the input type HIDDEN stuff it's doing?

Thanks!

----------

