我正在我的应用中添加一项新功能,让用户可以分步完成流程。
步骤1 选择下拉值
点击下一步按钮并执行第 2 步(ajax 请求加载并渲染部分 View ,渲染 TreeView )
点击下一步按钮
第 3 步(通过 XMLHttpRequest 上传文件)
点击下一步按钮
第4步(发出另一个ajax请求来渲染部分 View ) 由于某种原因,此请求永远不会命中 Controller 操作方法。奇怪的是,如果我在步骤 2 中发布到操作方法,它将成功发布,但我对此步骤有不同的操作。
我在 IE 10 开发者工具中收到以下警告
SEC7127:CORS 请求的重定向被阻止。
XMLHttpRequest: Network Error 0x800c0014, A redirection problem occurred. SCRIPT7002: XMLHttpRequest: Network Error 0x800c0014, A redirection problem occurred.
上述错误似乎与这一步之前的XMLhhtprequest有关。我尝试将 XMLhttprequest 设置为 NULL 或尝试在其成功事件时将其处置。我不明白在第 4 步中我仍然可以发布到第 2 步的操作,但不能发布其他操作?
第3步
function handleFiles() {
var formdata = new FormData(); //FormData object
var xhr = new XMLHttpRequest();
xhr.open('POST', fileUploadURL);
xhr.setRequestHeader('Content-type', 'multipart/form-data');
//Appending file information in Http headers
xhr.setRequestHeader('X-File-Name', document.getElementById('myFile').files[0].name);
xhr.setRequestHeader('X-File-Type', document.getElementById('myFile').files[0].type);
xhr.setRequestHeader('X-File-Size', document.getElementById('myFile').files[0].size);
//Sending file in XMLHttpRequest
xhr.send(document.getElementById('myFile').files[0]);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
$("input[id=filestoredname]").val(xhr.responseText);
alert("file saved..");
}
}
return false;
}
var instrumentSelectionUrl = '@Url.Action("Step2", "ErrorCode")';//step2
var finalTreeViewUrl = '@Url.Action("renderFinalTree", "ErrorCode")';//step3
var fileUploadURL = '@Url.Action("UploadFiles", "ErrorCode")';//step3
$(function () {
$('form').stepy({
backLabel: '<<',
nextLabel: '>>',
finishButton: false,
next: function (index) {
alert(index);
var v = $("#InsIdLst").chosen().val();
if (v == null && index == 2) {
alert("Please select an Instrument");
return false;
}
if (v != null && index == 2) {
var overlay = $('<div></div>').prependTo('body').attr('id', 'overlay');
$.ajax({
type: 'POST',
url: instrumentSelectionUrl,
cache: false,
datatype: "html",
data: $("form").serialize(),
success: function (result) {
$("#errorCodes").html(result);
overlay.remove();
}
});
}
if (index == 4) {
alert("try..");
$.ajax({
type: 'POST',
url: finalTreeViewUrl,
cache: false,
datatype: "html",
data: $("form").serialize(),
success: function (result) {
$("#errorCodesSave").html(result);
}
});
}
}
});
});
最佳答案
所以在第 4 步中,如果我使用
$("#errorCodesSave").load(finalTreeViewUrl, { fileName: $("#filestoredname").val(), $("#InsIdLst").chosen().val();: 1 });
它不是 $Ajax,而是发布到预期的 Controller 操作。这对我来说已经足够好了。
关于jquery - 在 IE 10 中成功执行 XMLHttpRequest 后,无法立即通过 .Ajax 发布到新的操作方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32184394/