Angular 2'拒绝执行......'JSONP问题。

时间:2016-12-06 16:10:17

标签: json angular jsonp

我昨天擦了我的HD clean并安装了Windows 10专业版。

我安装了node / npm,git等..并在我正在Windows 8.1下工作的项目上运行了“npm install”。(有效)。

该项目依赖于连接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());
    }


}

1 个答案:

答案 0 :(得分:1)

我今天早些时候在AngularJS 1.x应用程序中遇到了同样的问题。我对该问题的理解是Behance Api没有在JSON请求的Content-Type头中返回正确的MIME类型。它目前以application/json的形式返回application/javascript or text/javascript。该错误来自Chrome,因为它是一个安全限制,并拒绝让代码以错误的MIME类型运行。我检查了一些其他的浏览器,Firefox似乎没问题。所以我认为你的任何事情都没有。您可以像我一样提交请求here,希望他们尽快解决。希望这有帮助!