我在我的应用程序中添加了一项新功能,允许用户按步骤完成一个过程.
步骤1
选择下拉值
点击下一步按钮和第2步(ajax请求加载并呈现局部视图,呈现树视图)
点击下一步按钮
点击下一步按钮
第4步(另一个ajax请求呈现局部视图)
由于某种原因,此请求永远不会达到控制器操作方法.奇怪的是,如果我在步骤2中发布操作方法,它将成功发布,但我对此步骤有不同的操作.
我在IE 10 Developer工具中收到以下警告
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,success: function (result) {
- $("#errorCodesSave").html(result);
- }
- });
- }
- }
- });
- });
解决方法
所以在第4步,如果我使用
- $("#errorCodesSave").load(finalTreeViewUrl,{ fileName: $("#filestoredname").val(),$("#InsIdLst").chosen().val();: 1 });
而不是$Ajax,它确实发布到预期的控制器操作.这对我来说足够好.