【问题标题】:Access to XMLHttpRequest at 'http://localhost:3000/framework/create' from origin 'http://localhost:4200' has been blocked by CORS policy从源“http://localhost:4200”访问“http://localhost:3000/framework/create”处的 XMLHttpRequest 已被 CORS 策略阻止
【发布时间】:2018-12-09 06:31:00
【问题描述】:

我有一个错误

从源“http://localhost:4200”访问“http://localhost:3000/framework/create”处的 XMLHttpRequest 已被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:没有“Access-Control-Allow-Origin”标头出现在请求的资源上。

我该如何解决?

我使用 angular v7 和 express.js 作为后端

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Injectable({providedIn : 'root'})
export class CommonService {

  uri = 'http://localhost:3000/framework';

  constructor(private http: HttpClient) { }

  addFramework(framework, bahasa) {
    const obj = {
      framework: framework,
      bahasa: bahasa
    };
    console.log(obj);
    this.http.post(`${this.uri}/create`, obj)
        .subscribe(res => console.log('Done'));
  }


}

【问题讨论】:

    标签: angularjs express


    【解决方案1】:

    如果您使用的是 chrome,请转到 https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi 并安装它。刷新页面,它应该可以工作了。

    【讨论】:

    • 如果我使用的是 firefox?
    猜你喜欢
    • 2019-10-31
    • 2020-01-26
    • 2021-10-05
    • 2020-10-12
    • 2021-03-08
    • 2020-07-09
    • 1970-01-01
    • 2019-11-17
    • 2020-11-11
    相关资源
    最近更新 更多