Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-29-2012, 01:03 AM   PM User | #1
q1h
New Coder

 
Join Date: May 2011
Posts: 34
Thanks: 7
Thanked 0 Times in 0 Posts
q1h is an unknown quantity at this point
Jquery PHP download displaying odd characters

I have a JQuery form:

Code:
      $("#download").live("submit", function () {
        $.ajax({
            type: "POST",
            cache: false,
            url: "download.php",
            data: $(this).serialize(),
            success: function (data) {
                $('#result').html(data);
            }
        });
        return false;
    });
Which submits to a PHP file:

PHP Code:
<?php
$file 
$_POST['file'];
$url '/uploads/' $file '.zip';
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=x.zip");
header("Content-Type: application/zip");
header("Content-Transfer-Encoding: binary");
readfile$url );
exit();
?>
Which outputs garbled text into my "#result" div. I'm positive that the PHP is executing properly, but how can I get JQuery to prompt the download instead of reading as text? When I delete "$('#result').html(data);" nothing happens at all, and I can't just link to the PHP file because the form submits file-specific info. Thanks ...
q1h is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:38 PM.


Advertisement
Log in to turn off these ads.