简体   繁体   English

在没有Ajax或jQuery的情况下在IE9 / Angular 5 / TypeScript上使用FormData

[英]Using FormData on IE9/Angular 5/TypeScript without Ajax nor jQuery

In my application Angular 5 / Typescript , I have an UploadFile component looks like : 在我的应用程序Angular 5 / Typescript中 ,我有一个UploadFile组件,如下所示:

component.html

....
<form #formUpload id="formUpload">
   <input type="file" class="input-file-ghost" (change)="onChangeFile($event.target.files)">
</form>
....

component.ts

export class UploadFileComponent implements OnInit {

  @Input() .....;
  @Output() filesAdded = new EventEmitter<File>();
  @ViewChild('formUpload') formUpload: ElementRef;
  ...

  constructor() { .... }

  ngOnInit() { .... }

  onChangeFile(files: File[]) { ..... }
}

Use case

<app-upload-file
        [uploadFileConfig]="...."
        (filesAdded)="....">
 </app-upload-file>

**********

formCvData: FormData = new FormData();
onFileUploaded($event) {
  const uploaded = $event;
  this.formLmData.set('.....', uploaded, uploaded.name);
}

Work fine when this component is used on Chrome and Mozilla browsers, but when I go on IE 9 I have this error : 在Chrome和Mozilla浏览器上使用此组件时,工作正常,但是在IE 9上运行时出现此错误:

'FormData' is undefined 'FormData'未定义

I looked in the git issues and Stackblitz projects, I have't found anything that can solve the problem with a modern solution. 我查看了git问题和Stackblitz项目,但没有找到任何可以用现代解决方案解决问题的方法。

IMPORTANT : I am looking for a solution that does not use jQuery nor Ajax 重要提示:我正在寻找不使用jQueryAjax的解决方案

Thank you in advance for your help. 预先感谢您的帮助。

FormData is not available in IE9: FormData在IE9中不可用:

https://developer.mozilla.org/en-US/docs/Web/API/FormData#Browser_compatibility https://developer.mozilla.org/en-US/docs/Web/API/FormData#Browser_compatibility

You will have to manually gather and encode the form data yourself. 您将必须自己手动收集和编码表单数据。

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

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