Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Rails:使用jquery从ajax get请求下载zip文件_Javascript_Jquery_Ruby On Rails_Ajax - Fatal编程技术网

Javascript Rails:使用jquery从ajax get请求下载zip文件

Javascript Rails:使用jquery从ajax get请求下载zip文件,javascript,jquery,ruby-on-rails,ajax,Javascript,Jquery,Ruby On Rails,Ajax,我正在尝试下载一个文件作为zip。我发送ajax请求,作为响应,我想发送一个zip文件。但我有一个错误。我的ajax请求如下 $( "#test-id" ).on( "click", function() { $.ajax({ type: "GET", url: "<%= articles_download_path %>", dataType:"application/zip", success: functi

我正在尝试下载一个文件作为zip。我发送ajax请求,作为响应,我想发送一个zip文件。但我有一个错误。我的ajax请求如下

$( "#test-id" ).on( "click", function() {
    $.ajax({
        type: "GET",
        url: "<%= articles_download_path %>",
        dataType:"application/zip",
        success: function (result) {
           window.alert("success!!");
        },
        error: function (){
            window.alert("something wrong!");
        }
    });
});
我的日志中没有错误,但在我的浏览器控制台中会给出如下响应

PK����8dJH�/���
��������after upgrade 30.xlsx�W8\��u�0�(�A��Q��-!zDI0:3�^B�%����D��Ddt!z�������e�{�s�9��g
���W�k���I@H��H�Ǫ����V����c�n0'�����0��n�"|CF��Q��I&������C�ʘo�q��ke�XڑPJ�잝L5aNhlv�eU   V�D
ʟK�]����E�0Ё���s�9\�!��[RYqR%Ke�K���%5^�
还有我的日志

Started GET "/articles/download?locale=en" for 127.0.0.1 at 2016-02-10 12:33:48 +0100
Processing by ArticlesController#download as */*
  Parameters: {"locale"=>"en"}
.
.
.
 Rendered text template (0.0ms)
Sent data articles.zip (1.0ms)
Completed 200 OK in 431ms (Views: 1.0ms | ActiveRecord: 5.0ms)

我认为我对zip文件的ajax请求格式不正确。但我在网上找不到任何其他东西。如何解决此问题?

您是否能够通过在浏览器中加载
文章\u下载\u路径
手动下载zip?这应该告诉您问题是否在Rails代码中。
Started GET "/articles/download?locale=en" for 127.0.0.1 at 2016-02-10 12:33:48 +0100
Processing by ArticlesController#download as */*
  Parameters: {"locale"=>"en"}
.
.
.
 Rendered text template (0.0ms)
Sent data articles.zip (1.0ms)
Completed 200 OK in 431ms (Views: 1.0ms | ActiveRecord: 5.0ms)