发送Promise请求出现以下错误origin ‘null‘ has been blocked by CORS policy

2023-05-16

错误如下

Access to XMLHttpRequest at 'http://localhost:9090/data' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

问题

出现了跨域访问问题

解决方法

用express设置允许跨域访问服务,代码如下:

// 引入express框架
var express=require("express");
// 创建web服务器
var app=express();
// 设置允许跨域访问该服务
app.all('*', function (req, res, next) {
	res.header('Access-Control-Allow-Origin', '*');
	res.header('Access-Control-Allow-Headers', 'Content-Type');
	res.header('Access-Control-Allow-Methods', '*');
	res.header('Access-Control-Allow-Headers', 'X-Requested-With');
	next();
});

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

发送Promise请求出现以下错误origin ‘null‘ has been blocked by CORS policy 的相关文章

随机推荐

  • request for member in , which is of pointer type

    原因 其实就是因为结构体成员引用符 34 34 和指针的箭头运算符 gt 用错了 只要根据自己的代码把 点 和 gt 改回去就行了
  • 结构体对齐问题(转)

    一个结构体变量定义完之后 xff0c 其在内存中的存储并不等于其所包含元素的宽度之和 例一 xff1a span class token macro property span class token directive keyword i
  • java.net.SocketException: Broken pipe (Write failed)发生原因及其解决办法

    先运行B main 再运行A main 先运行B的main xff0c 然后由于B有accepte的执行 xff0c 所以B那块先阻塞 xff0c 然后点击执行A main的时候会执行A的socket连接 xff0c 然后B监听到了之后立即
  • Matlab进行多项式拟合

    觉得有用的先点赞后收藏 xff0c 不要只收藏不点赞 xff01 xff01 1 一个坐标系里面绘制多个函数图像 clear clc x span class token operator 61 span span class token
  • K-Means聚类算法及其python实现(已附上代码至本博客)

    目录 一 算法公式讲解二 算法流程三 算法实现代码四 代码结果分析五 K Means库函数六 K Means算法时间复杂度 一 算法公式讲解 对于 n代表了x有n维 xff0c x上标j表示第j维的特征 xff0c 下标i表示该向量是第i个
  • The server quit without updating PID file

    我本地Mac电脑爆的错误 xff01 xff01 xff01 总体解决办法有两个 xff0c 方法一 1 可能是 usr local MySQL data mysqld pid文件没有写的权限 解决方法 xff1a 给予权限 xff0c 执
  • Could not find artifact com.github.pagehelper:pagehelper-spring-boot:jar:1.4

    我的情况是导入1 4 2版本的pagehelper spring boot就爆错 xff0c 但是导入了1 3 0版本的pagehelper spring boot就不爆错了 xff0c 后面又导入了一次1 4 2版本的pagehelper
  • No primary or single public constructor found for interface java.util.List

    我的爆错原因是途中ids忘记标注注解 64 PathVariable了 xff0c 因为要传入一系列的整数的列表对象到路径 emps deleteEmps ids 中 xff0c 所以我这里就是加上注解 64 PathVariable就OK
  • 数据结构之用堆栈判断回文

    回文判断 回文是指正读反读均相同的字符序列 xff0c 如 abba 和 abdba 均是回文 xff0c 但 good 不是回文 编写一个程序 xff0c 使用栈判定给定的字符序列是否为回文 输入格式 输入待判断的字符序列 xff0c 按
  • 单片机外部中断实验

    目录 1 概述 2 原理 3 硬件和软件设备 4 步骤 5 结果 xff08 分析 xff09 1 概述 联系程序设计 xff0c 并熟悉外部中断和按钮的使用 xff1b 掌握单片机外部中断程序的设计方法 xff1b 在外部中断0处接一个开
  • 自定义Rust安装路径,自定义安装Rust

    首先我们知道使用https www rust lang org zh CN tools install官方下载器下载安装的rust主要有两个文件夹 xff0c 而且会默认生成到C盘下 但是 xff0c 我们通过修改环境变量可以自定义安装路径
  • HTML基础(一)

    本文是作者在学习html过程中对知识的初步整理 1 第一个程序 span class token doctype lt DOCTYPE html gt span span class token tag span class token t
  • 结构体的数组

    结构数组 也就是结构体的数组 的组成 xff1a struct 结构名 变量名 数组大小 span class token macro property span class token directive hash span span c
  • kali详细安装教程

    vmware虚拟机下载地址 xff1a https www vmware com cn products workstation pro workstation pro evaluation html kali ISO镜像 https cd
  • Armbian (jammy) 上安装 Docker

    一 Armbian 的软件源配置 Ubuntu 的软件源配置文件是 etc apt sources list 默认注释了源码镜像以提高 apt update 速度 xff0c 如有需要可自行取消注释 deb https mirrors tu
  • c语言结构体中的冒泡排序

    题目 xff1a 使用结构体以及函数 xff0c 首先录入学生信息 xff0c 依据学生成绩 xff0c 对学生相关信息进行排序 include lt stdio h gt include lt string h gt struct stu
  • csp序列查询(C语言)

    csp序列查询 span class token macro property span class token directive hash span span class token directive keyword include
  • 数据库学习

    数据库学习 一 span class token keyword SELECT span span class token operator span span class token keyword FROM span customers
  • Spring框架-ioc和JdbcTemplate

    前提 xff1a 我们用了Mybatis时 xff0c 已经不需要再使用其他的持久层框架了 用了mybatis之后 xff0c 我们只需要写持久层接口以及sql语句即可 但是为了讲解spring中的事务 xff0c 我们把JdbcTempl
  • 发送Promise请求出现以下错误origin ‘null‘ has been blocked by CORS policy

    错误如下 Access to XMLHttpRequest at span class token string 39 http localhost 9090 data 39 span from origin span class toke