2011-12-13 63 views
1

我正在使用valums Ajax上傳來上傳圖片。我在同一頁面上有多個上傳按鈕。在FF,Chrome,IE8和Opera上一切都很完美。但是,在safari中沒有任何反應,也沒有上傳文件。我正在使用ajaxupload.3.6.js,下面是我的代碼 -valums Ajax上傳不能在Safari上工作

 button = $("#uplaodFile1");  
      new AjaxUpload(button, { 
      action : '/business/upload_file1', 
      name: 'uplaodFile1', 
      autoSubmit: true, 
      cache:false, 
      onSubmit: function (file, ext) { 

       if (!(ext && /^(jpg|gif|png)$/i.test(ext))) { 
        alert('Error: invalid file extension'); 
        return false; 
       } 

      }, 
      onComplete: function (file, response) { 
       if(response=="Sucess") { 
        alert(response + 'sucess'); 
        } 

       else { 
         alert(response); 
        } 

      } 
     }); 

有沒有人遇到過這個問題。我嘗試了所有的選項,例如添加元標記,搜索空的src屬性和url屬性,但沒有任何幫助。

回答

0

這是一個老問題,但是這仍然是一個非常惱人的Safari瀏覽器的問題。見Safari XHR upload stucks (sometimes)JQuery Ajax call often not working on Safari 6

好新鮮的是:你可以建立所提出的解決辦法在Valums fileuploader.js所提供的鏈接解釋說:

如何?在插件qq.FileUploader的xhr.open前的功能_upload添加一個Ajax調用,包括在阿賈克斯」更迭函數的所有代碼,直到xhr.send:

$.ajax({ 
    async: false, 
    url: your_closeconnection_script 
}) 
.success(function(data){ 
    xhr.open(... 
    ... 
    xhr.send(file); 
}); 

一兩件事:你需要創建的變量「這個」 Ajax調用之前和更換所有出現在成功的功能:

var $this = this; 
$.ajax({ 
    async: false, 
    url: your_closeconnection_script 
}) 
.success(function(data){ 
    xhr.open(... 
    ... 
    if ($this._options.encoding == 'multipart'){ 
     ... 
    } 
    ... 
    xhr.send(file); 
}); 

的Et瞧:平穩的工作Valums插件!