【问题标题】:angular $http make form submit file fail角度 $http 使表单提交文件失败
【发布时间】:2014-01-14 01:13:58
【问题描述】:

这是我的代码: 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-控制器:

$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模式下,它也成功地将文件传输到网络服务器。 为什么 $http 会影响 load() 机制。 实际上,way1 之前工作过,就在昨天它失败了,并且再也没有工作过。

【问题讨论】:

标签: javascript forms angularjs upload submit


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2018-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-15
    • 2016-03-01
    • 2014-09-12
    • 1970-01-01
    • 2020-01-31
    相关资源
    最近更新 更多