CORS两种跨域方法示例讲解
程序员文章站
2022-03-07 22:14:43
ajax1.0
const http=require('http');
let httpserver=http.createserver((req,re...
ajax1.0
const http=require('http'); let httpserver=http.createserver((req,res)=>{ res.setheader('access-control-allow-origin','*'); res.write('aaaa'); res.end(); }); httpserver.listen(8080);
ajax2.0
const http=require('http'); let allowhosts=['taobao.com','baidu.com']; let httpserver=http.createserver((req,res)=>{ if(allowhosts.indexof(req.headers['origin'])!=-1){ res.setheader('access-control-allow-origin','*'); } res.write('aaaa'); res.end(); }); httpserver.listen(8080);