Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Ajax to download a file

jsteeljsteel Posts: 1Member
Hi

I would like to download a file in an asynchronous manner. From what I
have read, I should be using a hidden iframe. How do I connect the AJAX
request to the iframe to display the file?

Thanks

Comments

  • mac_doggiemac_doggie Posts: 488Member
    Of you use AJAX to download the file, you don't need an Iframe. If you do use an IFrame, you don't need AJAX. It's one of the two... I would prefer AJAX, simply because it gives you more freedom... Except it you want to display a full page including head and body tags and included scripts from a third party, then I would suggest using an IFrame so you can really seperate it from your own HTML and the scripts won't conflict etc.

    If you're a beginner with AJAX, I could really recommend to use some JavaScript Framework with build in AJAX support like mootools, scriptaculous or jquery. I never used jquery, but I did use mootools and scriptaculous and I would say that mootools is easier to master because documentation is very good on their site. scriptaculous is also very powerfull and some say even better then mootools (http://mootools.net/), but if you're not allready a guru, you need to put in a lot of time to google for examples on everything..., So I would say check out mootools and try something like this:

    [code]


    function GetMyAJAXFile() {
    var myHTMLRequest = new Request.HTML({
    url:'myDocument.html',
    onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript) {
    // This will b e triggered after the document is loaded succesfully
    //
    $('MyDiv').innerHTML = responseHTML;
    }
    }).post();
    }

    [/code]

    The dollar function is short for document.getELementById() very handy and you'll use that one quite often. With this example you'll get the data and place it inside a div element. No Iframe needed. Make sure the document you load is just HTML without around it, because it will be rendered inside the current HTML file.

    Hope this helps ya out. (I didn;t test the example above, but it will steer you in a direction I hope. Check out the documentation on the mootools.net site for more cool stuff you can do with it.)
    ;-)
    -mac-
    mailto:mac_doggie@hotmail.com
    the Netherlands...
Sign In or Register to comment.