访问通过JavaScript提交表单时,在IE拒绝错误 [英] Access denied error in IE when submitting form through javascript

查看:248
本文介绍了访问通过JavaScript提交表单时,在IE拒绝错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@using (Html.BeginForm("Upload", "MyProfile", FormMethod.Post, new
{
    @encType = "multipart/form-data",
    id = "ImgForm",
    name = "ImgForm",
    target = "UploadTarget"
}))
{   
    <input type="file" name="FileUpload" class="filestyle-notext fileupload">                
}

<iframe id="UploadTarget" name="UploadTarget" style="position: absolute; left: -999em; top: -999em;"></iframe>

和通过JavaScript / jQuery的,我做的表格文件输入的改变提交。

And through javascript/jquery, I am doing form submit on change of file input.

$('.myprofile .fileupload').change(function () {       
    $('#ImgForm').submit();
});

它抛出一个错误:访问被拒绝,而且只在IE中发生(我使用IE8),并在Firefox正常工作,铬

It throws an error: Access is denied and It happens only in IE (i am using ie8) and works fine in firefox, chrome.

在论坛上我看到有一个与形式的问题,通过javasript在IE中提出,由于安全方面的原因,但有没有什么解决办法看完之后?我不明白为什么地狱只有IE浏览器,当所有浏览器都支持它。是IE不是所有的浏览器更安全? ;)在游泳池您的建议,请

After reading in forums I see there is an issue with form submit through javasript in IE due to security reasons but is there any workaround ? And I don't understand why the hell only IE does that when all browsers are supporting it. Is IE more secure than all browsers ? ;) Pool in your suggestions please.

推荐答案

IE8不支持调用从内部包含文件输入表单的 .submit()事件此文件输入的 .change()事件。这是出于安全考虑。您正在尝试将文件提交到服务器,而无需用户明确不允许这样做。一个可能的解决方法是调用 .submit()的形式从一些按钮,你放置的。点击()事件中的:

IE8 doesn't support invoking the .submit() event of a form containing file inputs from within the .change() event of this file input. This is for security reasons. You are attempting to submit a file to the server without the user explicitly allowing this. One possible workaround is to call the .submit() on the form from within a .click() event of some button you have placed:

$('.uploadButton').click(function () {       
    $('#ImgForm').submit();
});

现在,当用户点击某些上传按钮的形式将提交。

Now when the user clicks on some upload button the form will submit.

这是值得一提的是,这只是与IE8问题。更高版本以及其他浏览器没有这个限制。

It's worth mentioning that this is only problematic with IE8. Higher versions and other browsers do not have this limitation.

你也可以如 Uploadify 或的 blueImp文件上传上传文件到服务器在一个跨浏览器的方式。

Also you may consider using a Flash based upload control such as Uploadify or BlueImp File upload to upload files to the server in a cross browser way.

这篇关于访问通过JavaScript提交表单时,在IE拒绝错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆