SCRIPT5: 访问被拒绝,IE09和IE10

4

我正在使用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 浏览器中遇到了问题。JavaScript 控制台会报 "SCRIPT5: Access is denied." 的错误。
我已经尝试允许文件夹位置的权限,但没有效果。 C:\Users[USERNAME]\AppData\Local\Microsoft\Internet Explorer\DOMStor C:\Users[USERNAME]\AppData\Local\Packages\windows_ie_ac_001\AC\Microsoft\Intern‌​et Explorer\DOMStore 有什么建议吗?
谢谢。

2
你的问题在于点击提交的顺序。请看这里 - Kolya Ay
如果你使用jQuery,为什么要使用内联事件处理程序?另外,请记住live()已被弃用或删除。 - Eddie Monge Jr
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中测试过)


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接