Ajax错误处理
2024-09-08 08:53:23
控制台报的错误是:
Access to XMLHttpRequest at 'http://localhost:3000/error' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
GET http://localhost:3000/error net::ERR_FAILED
而不是400状态码
所以我们需要在app.js文件中加入
app.all('*', function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
res.header("X-Powered-By", ' 3.2.1')
res.header("Content-Type", "application/json;charset=utf-8");
next();
}); app.get('/error', (req, res) => {
res.status(400).send('not ok'); })
这样就解决了这个问题
最新文章
- java1.8函数式编程概念
- 升级win8.1后mysql服务不能启动的问题
- js中的this指针(四)
- Address already in use: JVM_Bind<;null>;:8080错误的解决办法
- Linux共享内存(一)
- mysql事务问题
- 新浪微博授权时出现";关注 *** 的微博";
- Deep learning From Image to Sequence
- 配置两个Hadoop集群Kerberos认证跨域互信
- spark submit参数调优
- 基于opencv和QT的摄像头采集代码( GoQTtemplate3持续更新)
- python rabittmq 使用
- 【存储过程】用SQL语句获得一个存储过程返回的表
- html基础代码示例
- part1:7-Linux网络配置
- Python 中单双引号
- 一个完成的spring xml配置文件
- ubuntu下超强的截图工具scrot
- 019——VUE中v-for与computer结合功能实例讲解
- 内存修改之IOS版ce