nginx跨域
<br /><br />module.exports = function (app) { //设置跨域访问 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('/getdata', function(req, res) { // res.send({id:req.params.id, name: req.params.password}); // res.send("hello"); res.json("hello"); }); }<br /><br />
const express = require('express') const app = express() const api = require('./api') api(app) app.listen(8889) console.log("listen on port 8889");
<br />$.ajax({ dataType: 'json', url: 'localhost:8889/server', type:'get', success: function(data){ console.log(data); } });
node后台,前端nginx服务器ajax访问,出现跨域问题,使用nginx反向代理
相关推荐
liuxudong00 2020-11-19
wwzaqw 2020-11-11
lihaoxiang 2020-11-05
CrossingX 2020-11-04
xuegangic 2020-10-17
fanxiaoxuan 2020-09-17
安卓猴 2020-09-12
惠秀宝 2020-09-08
wwzaqw 2020-09-04
chenyingSunny 2020-09-04
是nsacer先森的 2020-09-03
bigname 2020-08-25
gaoqiang00 2020-08-24
灵均兰草 2020-08-20
xjp 2020-08-17
webgm 2020-08-16
wiky 2020-08-05
歆萌 2020-08-03
89961330 2020-07-28