我在IE中通過隱藏的iFrame上傳文件時遇到了一些問題。其實文件上傳工作正常,但我的jQuery代碼顯示成功對話框並添加鏈接到表不會觸發。使用IE開發人員工具,我發現SCRIPT70:Permission denied錯誤消息。這在Chrome中運行良好,所以我對在IE中遇到的問題不知所措。我應該提到我使用的是IE10,所以我想這個問題也存在於以前的IE版本中。SCRIPT70:權限被拒絕在IE中訪問iFrame
基本上我想要做的就是使用隱藏的iFrame來模擬Ajax文件上傳,因爲我們必須支持傳統瀏覽器。當iFrame發佈成功時,其響應中包含一個包含我讀取然後解析的JSON的div。來自JSON的數據用於向用戶顯示一條消息,指示文件上傳的狀態,並通過向表中添加一行來將鏈接添加到頁面。然而,在IE瀏覽器中,chechUploadResponse函數甚至不會觸發。
的Javascript:
$(document).ready(function()
{
$('#btnPrint').click(openPrintTimesheetWindow);
$('#date').change(postback);
$('#employee').change(postback);
$('#client').change(postback);
$('#btnUpload').click(uploadFile);
$("#uploadFrame").on("load", function() {
$('#uploadFrame').contents().find('#userFile').change(uploadFileChanged);
checkUploadResponse();
});
});
function postback()
{
$('#timesheetPrintFilter').submit();
}
function uploadFileChanged()
{
$('#ajaxBusy').show();
$('#uploadFrame').contents().find('#uploadForm').submit();
}
function uploadFile()
{
var employeeId = $('#init_employee').val();
var periodDate = $('#init_periodEndDate').val();
$('#uploadFrame').contents().find('#employeeId').val(employeeId);
$('#uploadFrame').contents().find('#periodEndDate').val(periodDate);
$('#uploadFrame').contents().find('#userFile').click();
}
function checkUploadResponse()
{
var response = $('#uploadFrame').contents().find('#uploadResponse').text();
if (response != null && response != '')
{
var response = jQuery.parseJSON(response);
if (response.status == "ERROR")
{
$("#dialog").html(response.message);
$("#dialog").dialog({ buttons: { "OK": function() { $(this).dialog("close");}}, title: "Error" });
}
else
{
$("#dialog").html(response.message);
$("#dialog").dialog({ buttons: { "OK": function() { $(this).dialog("close");}}, title: "Success" });
var url = response.url;
var tsaid = response.tsaid;
var name = response.name;
var row = '<tr id="tsaid-' + tsaid + '">' +
'<td width="80%" valign="top" align="left">' +
'<a href="' + url + '">' + name + '</a>' +
'</td>' +
'</tr>';
$("#tsAttachment").append(row);
}
}
$('#ajaxBusy').hide();
}
隱藏的iframe:
<form id="uploadForm" name="uploadForm" action="timesheet-upload.php" method="POST" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="3145728" />
<input type="hidden" name="employeeId" id="employeeId" value="" />
<input type="hidden" name="periodEndDate" id="periodEndDate" value="" />
<input type="file" name="userFile" id="userFile" />
</form>
下面是隱藏的iframe被張貼
<div id="uploadResponse">{"status":"SUCCESS","message":"Timesheet successfully uploaded","url":"uploads\/2013\/Aug\/1-49cd1c0217abf676505b349ec88bb5a42b1d5631e41232f08be3b0dced9f65e2.pdf","name":"How To Write A Cover Letter.pdf","tsaid":15}</div>
<form id="uploadForm" name="uploadForm" action="timesheet-upload.php" method="POST" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="3145728" />
<input type="hidden" name="employeeId" id="employeeId" value="" />
<input type="hidden" name="periodEndDate" id="periodEndDate" value="" />
<input type="file" name="userFile" id="userFile" />
</form>
事實證明,這可能是一個jQuery錯誤。我從jQuery-1.9.1升級到jQuery-1.10.2,這似乎解決了我的問題。我發現這個報告在jQuery網站上有興趣的人。希望這有助於任何有類似問題的人。 http://bugs.jquery.com/ticket/13936 – greyfox