request faild #705
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I use angualr2 and my backend is koa2,when i use ng2-file-upload,there is my TS code `import { Component } from '@angular/core';
import { UserService } from './server';
import {FileUploader} from "ng2-file-upload";
@Component({
moduleId: module.id,
selector: 'my-edit',
templateUrl: '../templates/editpage.html',
styleUrls: ['../css/editPage.min.css'],
providers: [UserService]
})
export class EditPage {
title:any;
content:any;
image:any;
author:any;
url:any = 'http://localhost:3005/api/createTodayFocus';
data:any = {};
closeResult: string;
tip:any = '';
type:any = 0;
constructor(private userService: UserService) { }
submitAll(content){
this.data = {title:this.title,content:this.content,image:this.image,author:this.author,type:this.type};
this.userService.postNewsData(this.url,this.data)
.subscribe(
data =>{
console.log(data);
this.tip = data;
this.title = '';
this.content = '';
this.image = '';
this.author = '';
this.type = '0';
}
)
}
}
and HTML code<input type="file" ng2FileSelect [uploader]="uploader" multiple /><br/> <p *ngFor="let item of uploader.queue"> {{item?.file?.name}} <button type="button" class="btn btn-success btn-xs" (click)="item.upload()" [disabled]="item.isReady || item.isUploading || item.isSuccess"> <span class="glyphicon glyphicon-upload"></span> Upload </button> </p>when i upload image,return this
XMLHttpRequest cannot load http://localhost:3005/api/uploadImage. Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Credentials' header in the response is '' which must be 'true' when the request's credentials mode is 'include'. Origin 'http://localhost:4200' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.My backend have already fixed cors, so, why?
try this
credit : https://github.com/valor-software/ng2-file-upload/issues/399
thanks for @Wizz14
thanks for @Wizz14 ...!!
thanks @Wizz14 !!!