1
我使用jquery form來上傳沒有頁面刷新的圖像。以下是html標記:自動文件上傳使用jQuery表單提交在IE瀏覽器中拋出訪問被拒絕錯誤
<a href="javascript:void(0);" onclick="UpdateImage();">
<img src="@_fullImgPath" name="img-uploader" alt="" title="" /></a>
@using (Html.BeginForm("UpdateImage", "Profile", FormMethod.Post, new { id = "img-file-upload-form", @class = "form", autocomplete = "off", enctype = "multipart/form-data" }))
{
@Html.Hidden("UpdateImageId")
<input type="file" name="file" id="file" />
}
<script language="javascript" type="text/javascript">
$(function() {
$("#img-file-upload-form").ajaxForm({
iframe: true,
dataType: "json",
beforeSubmit: function() {
},
success: function (result) {
alert('done');
},
error: function (xhr, textStatus, errorThrown) {
alert('error');
}
});
$("#file").change(function() {
$("#img-file-upload-form").submit();
});
});
function UpdateImage(id) {
$("input[id=file]").click();
}
</script>
這在Firefox和Chrome中運行良好,但在IE 8和9中,它會引發訪問被拒絕錯誤。 有沒有解決這個問題?或者有沒有頁面刷新上傳圖像的替代方法?
避免頁面刷新,我使用的是給ajaxForm。它會照顧ajax的實現。我使用的代碼除了在IE中工作。 – Prasad