2017-02-08 4 views
-1

ダウンロードしたzipファイルに問題が発生しています。アーカイブをクリックするたびに、「アーカイブは不明な形式か破損しています」というメッセージがスローされます。私は問題がコーディング(アーカイブの内容のフォーマット)にあると思う。助けてください!JSダウンロードしたアーカイブから「アーカイブが不明な形式か破損しています」

$.ajax({ 
    url: '/Unloading/' + $("#radioVal:checked").val(), 
    type: "POST", 
    data: { 'dateTimeTo': $("#dateTimeTo").val(), 'dateTimeFrom': $("#dateTimeFrom").val() }, 
    beforeSend: function() {$("#divLoading").show();}, 
    success: function (result) { 
     $("#divLoading").hide(); 
     if (result.length === 0) { 
      var message ="Error"; 
      $("#dialog-message").text(message); 
      $("#dialog-message").dialog({ 
       modal: true, 
       buttons: { 
        close: function() { 
         $(this).dialog("close"); 
        } 
       } 
      }); 
     } else { 
      var xmlstr, filename, bb; 
      filename = "UnloadedLeases.zip"; 
      bb = new Blob([result], { type: "application/zip" }); // I think somewhere here is a problem with the coding 

      var pom = document.createElement('a'); 
      pom.setAttribute("target", "_blank"); 
      pom.setAttribute('href', window.URL.createObjectURL(bb)); 
      pom.setAttribute("download", filename); 
      document.body.appendChild(pom); 
      pom.click(); 
      document.body.removeChild(pom); //removing the element a from the page 
     } 
    }, 

答えて

0

私の知る限りでは、$.ajaxは、あなたが(それはUTF-8からバイナリをデコードしようと、それ破損します)箱から出してバイナリコンテンツをダウンロードすることはできません。 jQueryプラグイン(jquery.binarytransport.jsなど)を使用するか、xhrを直接使用してください(responseType)。

$.ajax({ 
    url: '/Unloading/' + $("#radioVal:checked").val(), 
    type: "POST", 
    dataType: 'binary',      // using jquery.binarytransport.js 
    // ... 

    success: function (result) { 
     // Default response type is blob 
     if (result.size === 0) { // instead of length for blobs 
      // ... 
     } else { 
      var bb = result; // already a blob 
      // ... 
     } 
    } 
}) 
+0

どうもありがとうございました! – DevFoals

関連する問題