{"id":1497,"date":"2022-08-30T15:17:01","date_gmt":"2022-08-30T15:17:01","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/23\/ajax-issue-uncaught-syntaxerror-when-processing-zip-file-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:17:01","modified_gmt":"2022-08-30T15:17:01","slug":"ajax-issue-uncaught-syntaxerror-when-processing-zip-file-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/ajax-issue-uncaught-syntaxerror-when-processing-zip-file-collection-of-common-programming-errors\/","title":{"rendered":"AJAX issue &#8211; Uncaught SyntaxError when processing Zip File-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;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&#8217;m utilizing AJAX to accomplish this task.<\/p>\n<pre><code>    Build.prototype.ajaxHandler = function(method, values) {\n        jQuery.ajax({\n            type: 'POST',\n            url: WP_LOCALIZED['url'],\n            data: {\n                action:     'request_handler',\n                method:     method,\n                data:       values\n            }, success: function(data) {\n                var response = jQuery.parseJSON(data);\n                console.log(response);\n\n            }, error: function(XMLHttpRequest, textStatus, errorThrown) {\n                console.log(XMLHttpRequest, textStatus, errorThrown);\n            }\n        });\n    };\n<\/code><\/pre>\n<p>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 <code>Uncaught SyntaxError: Unexpected token<\/code> open(&#8216;test.zip&#8217;, ZipArchive::CREATE) === TRUE) { if($zip-&gt;addEmptyDir($this-&gt;_plugin_path . &#8216;assets\/temp_files&#8217;)) { \/\/ Do stuff } $zip-&gt;close(); } header(&#8216;Content-Type: application\/zip&#8217;); header(&#8216;Content-disposition: attachment; filename=filename.zip&#8217;); header(&#8216;Content-Length: &#8216; . filesize($zip)); readfile($zip); }<\/p>\n<p>Interestingly the same thing happens if I replace the <code>$this-&gt;zip_file()<\/code> call with just a basic <code>echo<\/code> statement. Except instead of telling me the <code>Unexpected token<\/code> is<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-23 09:51:36. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I&#8217;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&#8217;m utilizing AJAX to accomplish this task. Build.prototype.ajaxHandler = function(method, values) { jQuery.ajax({ type: &#8216;POST&#8217;, url: WP_LOCALIZED[&#8216;url&#8217;], data: { action: &#8216;request_handler&#8217;, method: method, data: values }, success: function(data) { [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1497","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1497","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1497"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1497\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1497"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1497"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1497"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}