XMLHttpRequest cannot load Response for preflight - this is an invalid redirect in angular2

I am using angular2

and calling web api using below method to post data.

and error

XMLHttpRequest cannot load Response for preflight is invalid redirect

public _apiPath: string = 'http://myapplicationapi.azurewebsites.net/';
post(data?: any, mapJson: boolean = true) {

    let headers = new Headers();
    headers.append('Content-Type', 'application/json');
    headers.append('dataType', 'jsonp');

    this.createAuthorizationHeader(headers);
    var uri;

    if (this._pageIndex) {
       uri = this._baseUri + '?pageIndex=' + this._pageIndex.toString() + '&pageSize=' + this._pageSize.toString();
    } else {
        uri = this._baseUri;
    }

    if (mapJson) {

        return this.http.post(uri, data, {
            headers: headers
        }).map(responce => <any>(<Response>responce).json());

    } else {
        return this.http.post(uri, data, {
            headers: headers
        });
    }
}

      

enter image description here

+3


source to share





All Articles