Angular 2 'Refused to execute from ..' JSONP 问题。

Angular 2 'Refused to execute from ..' JSONP issue.

我昨天擦干净了硬盘并安装了 Windows 10 pro。

我安装了 node/npm、git 等...和 ​​运行 "npm install" 我在 Windows 8.1 下工作的项目(有效).

该项目依赖于连接到 Behance.net API 的服务。

当我键入 "ng serve" 时,控制台出现错误。

Refused to execute script from 'http://www.behance.net/v2/users/dennisschafer/projects?api_key=myapikey&callback=__ng_jsonp__.__req0.finished' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled.

EXCEPTION: Response with status: 200 Ok for URL: null

请注意,这个项目昨天在我的其他环境下运行,此后我没有触及任何代码。

服务文件如下所示:

import {Injectable} from '@angular/core';
import {Jsonp} from '@angular/http';
import 'rxjs/Rx';

@Injectable()
export class BehanceService{
    private username:string = 'dennisschafer'; // dennisschafer
    private api_key = 'myapikey';

    constructor(private _jsonp: Jsonp) {

    }

    getProjects() {
        return this._jsonp.get('http://www.behance.net/v2/users/'+this.username+'/projects?api_key='+this.api_key+'&callback=JSONP_CALLBACK')
        .map(res => res.json());
    }


}

我今天早些时候在 AngularJS 1.x 应用程序中遇到了同样的问题。我对问题的理解是 Behance Api 没有在 Content-Type header 中为 JSONP 请求返回正确的 MIME 类型。它目前以 application/json 的形式回归,而它应该像我一样 application/javascript or text/javascript. The error is coming from Chrome as it's a security restriction and refuses to the let the code run with the wrong MIME type. I checked some other browsers and firefox seems to be ok with it. So I don't think there's anything to do on your end. You can submit a request here 并且希望他们尽快修复它。希望这对您有所帮助!