【问题标题】:SCRIPT5: Access is denied IE09 and IE10SCRIPT5:访问被拒绝 IE09 和 IE10
【发布时间】:2013-03-27 15:39:24
【问题描述】:

我正在使用 Rails 3.2.11。我已经实现了文件上传的概念。它在 Firefox 和 chrome 浏览器上运行良好。

表格

<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:\Users[用户名]\AppData\Local\Microsoft\Internet Explorer\DOMStor C:\Users[USERNAME]\AppData\Local\Packages\windows_ie_ac_001\AC\Microsoft\Intern‌​et Explorer\DOMStore

任何建议

谢谢

【问题讨论】:

  • 你的麻烦在于点击提交顺序。看看here
  • 如果您使用 jquery,为什么还要有内联事件处理程序?另外,请记住 live 已被弃用/删除。

标签: jquery internet-explorer file-upload ruby-on-rails-3.2


【解决方案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 中测试)

【讨论】:

    【解决方案2】:

    使用 iframe 上传文件,javascript 代码无法确定 IE10 中服务器响应的 HTTP 状态代码。

    https://cmlenz.github.io/jquery-iframe-transport/#section-13

    您必须返回一个成功响应并评估 json 数据以确定它是成功还是不响应。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-20
      • 1970-01-01
      • 1970-01-01
      • 2013-08-06
      • 2011-08-13
      • 1970-01-01
      • 2012-06-14
      相关资源
      最近更新 更多