2014-10-02 130 views
0

必須創建一個jQuery的文件上傳的上傳功能,在Firefox,Chrome和IE版本我上傳的作品超過9文件上傳與jQuery的blueimp文件上傳,不能在IE9工作

我已經嘗試強制iframe傳輸,由jQuery-fileupload插件doc推薦。 Fileupload完成他的任務,但他發送一個空的對象。所以,symfony發送關於文件的錯誤。 我這樣的上傳過程的工作:Backbone.js的+ require.js - > symfony的 - > Rackspace公司

   $(selector).fileupload({ 
       dataType: 'json', 
       autoUpload: true, 
       url: 'http://' + IM('site').get('domain') + '/' + window.PadawanSite.envPath + '/upload/adpost/img', 
       forceIframeTransport: true, 

       add: function (e, data) { 
        var id = e.target.id.substring(e.target.id.length - 2), 
         jqXHR = data.submit() 
          .success(function (result, textStatus, jqXHR) { 
           images.push({ 
            id: id, 
            original: result.publicUrl.original, 
            large : result.publicUrl.large, 
            medium : result.publicUrl.medium, 
            small : result.publicUrl.small 
           }); 
          }) 
          .error(function (jqXHR, textStatus, errorThrown) { 
           $('#picture_callback_' + id).removeClass('glyph icon-spinner2 icon-refresh-animate').addClass('glyph-05 icon-x-empty'); 
          }) 
          .complete(function (result, textStatus, jqXHR) { 
           if (textStatus === "success") { 
            var ad = IM('ad').toJSON(); 
            ad.images = images; 
            IM('ad').clear().set(ad); 
            IM('ad').save(ad); 
            if (IM('ad').toJSON()) { 
             $('#adpost_picture_img_' + id).attr("src", result.responseJSON.publicUrl.small); 
             $('#picture_callback_' + id).removeClass('glyph icon-spinner2 icon-camera icon-x-empty icon-refresh-animate').addClass('glyph-05 icon-v'); 
             $('#adpost_picture_visualize').removeAttr('disabled'); 
            } 
           } 
          }); 
        $('#adpost_picture_visualize').attr('disabled', 'disabled'); 
        $('#picture_callback_' + id).removeClass('glyph-05 icon-camera icon-x-empty').addClass('glyph icon-spinner2'); 
        $('#picture_callback_' + id).addClass('icon-refresh-animate'); 
        $('#adpost_picture_name_' + id).empty(); 
        $('#adpost_picture_name_' + id).append(data.files[0].name); 
       } 
      }); 

我的請求頭,把它交給symfony的。但是你可以看到內容長度等於0.所以這是問題,但他爲什麼這樣做呢?

X-Requested-With: XMLHttpRequest 
Host: sjus.local 
Request: POST /app_dev.php/upload/adpost/img HTTP/1.1 
Cache-Control no-cache 
User-Agent Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko 
Connection Keep-Alive 
Referer http://sjus.local/app_dev.php#postad/picture 
Accept-Encoding gzip, deflate 
Accept-Language en-us 
Content-Length 0 
Accept */* 

回答

1

這是IE8/9知道的限制,當你做一個跨域文件上傳的plugin's documentation site says

我曾經遇到過這個問題,特別是當插件嘗試從iframe中獲取響應時,我得到了「Permission denied」錯誤,這是因爲在我的情況下,該網站與同一個域中的子域名API。所以我可以使用選項「initialIframeSrc」來指定要在iframe中使用的document.domain(幸運我)。我做了這樣的事情:

dataType: 'text', 
forceIframeTransport: true, 
initialIframeSrc: "javascript:document.write('<script>document.domain=\"mydomain.com\";</script>')", 

這樣插件能夠從iframe內容中檢索響應。

希望這會有所幫助。

相關問題