跨域请求

2020-03-08  本文已影响0人  增商

JSONP
业务逻辑本地处理,数据在云端
cors 跨域资源共享


image.png
//html
    <h1>CORS</h1>
    <script>
      fetch("http://localhost:3000/")
        .then(response => response.json())
        .then(json => console.log(json));
    </script>
//配置express => server
const express = require('express');
const cors = require('cors');
const app = express();
app.use(cors())

app.get("/",(req,res,next)=>{
  res.json(['name','imycode']);
})
app.listen(3000,()=>{
  console.log("success");
})
image.png
image.png

参看:前端跨域请求及解决方案

上一篇下一篇

猜你喜欢

热点阅读