2013-04-05 84 views
4

我正在使用rails 3.2.11。我已經實現了文件上傳的概念。它使用Firefox和Chrome瀏覽器正常工作。SCRIPT5:訪問被拒絕IE09和IE10

形式

<iframe id="upload_target" name="upload_target" style="display:none;"></iframe> 
<%= form_tag(url_for(:action => 'add_image'), 
        :target => 'upload_target', 
        :id => 'add_image_form', 
        :enctype => 'multipart/form-data', :multipart=>true) do %> 
    <%= text_field 'image_asset', 'name', :size => [60,40].min, :maxlength => "60", :id => "focus", :style=>"display:none", :value=>"site_logo" %> 
    <%= text_field 'image_asset', 'image_type', :value=>"Icon",:style=>"display:none"%> 
    <input type="file" id="file" name="image_form_file" size="36" style="display:none;" /> 
    <a href="#" class="button" onclick="$('#file').click();">Upload a new logo image</a> 
    <a href="#" class="button green" onclick=" $('#add_image_form').submit();">Save</a> 
<% end %> 

JQuery的

$('#file').live("change",function() { 
     $('#add_image_form').submit(); 
     setTimeout(function(){ 
     $.ajax({ 
       type: "GET", 
       beforeSend: function(xhr){ xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'))}, 
       dataType: "html", 
       url: "/get_image", 
       data: "record_id=<%= @page.id%>&format=html", 

       success: function(data){ 
        $('#site_logo').html(data); 
        var new_image = $('#site_logo').find("img").attr('src'); 
       }, 
       error: function(){ 
       } 
      }); 
    }, 6000)  

我有一個問題只有在IE 9,IE瀏覽器10。 Java腳本控制檯拋出「SCRIPT5:訪問被拒絕」。

我已經嘗試允許文件夾位置的權限,但沒有用。 C:\用戶[名] \ AppData \本地\微軟\的Internet Explorer \ DOMStor C:\用戶[名] \ AppData \本地\包\ windows_ie_ac_001 \ AC \微軟\實習生等資源管理器\ DOMStore

任何建議

感謝

+2

你的麻煩是在點擊提交序列。看看[這裏](http://stackoverflow.com/a/14578385/1206628)。 – 2013-05-16 01:03:44

+0

爲什麼如果你使用jQuery,你有內聯事件處理程序?此外,請記住,實時已被棄用/刪除。 – 2013-05-23 20:37:27

回答

1

嘗試來包裝標籤標記您的按鈕錨:

<input type="file" id="file" name="image_form_file" size="36" style="display:none;" /> 
<label for="file" class="button">Upload a new logo image</label> 

點擊標籤,就會觸發文件輸入,而不Internet Explorer的形式無效。

(在IE9 & IE10測試)