繁体   English   中英

角$ http使表单提交文件失败

[英]angular $http make form submit file fail

这是我的代码:html:

<form enctype='multipart/form-data' name='biosUpload' method='POST' action='partials/uploadComplete.html' target='hiddenFrame' >
  <input type='file' name={{romName}} id='brwsUpld'  />
</form>
<button type="button"  ng-click="uploadFwImage()">upload</button>
<iframe name="hiddenFrame" frameborder="0"  iframe-upload  id="uploadIframe"></iframe>

注意:uploadComplete.html只是没有代码的html。

js-controller:

$scope.iframeFlag = false;

//submit form in $http's promise won't upload the file,
//just load uploadComplete.html into iframe, 
//but when submit form outside the $http's promise ,it works.
//the problem is code follows worked ago, but just yesterday I found it can't , I am so confused. 

//way1:
$http({
    method: 'GET',
    url: 'rpc/test.asp'
}).
success(function(data, status) {
        $scope.iframeFlag = true;
        document.forms["biosUpload"].submit();
}).
error(function(data, status) {});

//way2:
document.forms["biosUpload"].submit();

js指令:

define(['./module'], function (directives) {
    'use strict';
    directives.directive('iframeUpload', function(){
    var linkFn = function(scope, element, attrs) {
        element.bind('load', function (event) {
           console.log(scope.iframeFlag);
          if(scope.isStop)return;
          if(!scope.iframeFlag)return;
            scope.uploadComplete();

        });
    };
    return {
      restrict: 'EA',
      link : linkFn
    };
  });
});

问题:在Way1模式下,它只是将uploadComplete.html加载到iframe中。 在Way2模式下,它还将文件成功传输到Web服务器。 为什么$ http将影响load()机制。 实际上,way1以前工作过,直到昨天它失败了,再也没有工作。

我找到了解决此问题的方法。
提交按钮只是执行提交操作。
ajax请求在该操作之前完成。
我还没有找到$ http影响文件提交的原因。
如果您知道原因,请您不要回答。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM