AJAX issue – Uncaught SyntaxError when processing Zip File-Collection of common programming errors

I’m creating an application that will allow a user to fill out a form and then have a customized zip file downloaded for them upon submit. I’m utilizing AJAX to accomplish this task.

    Build.prototype.ajaxHandler = function(method, values) {
        jQuery.ajax({
            type: 'POST',
            url: WP_LOCALIZED['url'],
            data: {
                action:     'request_handler',
                method:     method,
                data:       values
            }, success: function(data) {
                var response = jQuery.parseJSON(data);
                console.log(response);

            }, error: function(XMLHttpRequest, textStatus, errorThrown) {
                console.log(XMLHttpRequest, textStatus, errorThrown);
            }
        });
    };

Whenever I try to return basic data with my ajax handler I am able to successfully return without issue, but when I try to process my zip file method I consistently get Uncaught SyntaxError: Unexpected token open(‘test.zip’, ZipArchive::CREATE) === TRUE) { if($zip->addEmptyDir($this->_plugin_path . ‘assets/temp_files’)) { // Do stuff } $zip->close(); } header(‘Content-Type: application/zip’); header(‘Content-disposition: attachment; filename=filename.zip’); header(‘Content-Length: ‘ . filesize($zip)); readfile($zip); }

Interestingly the same thing happens if I replace the $this->zip_file() call with just a basic echo statement. Except instead of telling me the Unexpected token is

Originally posted 2013-11-23 09:51:36.