美文网首页
跨域请求

跨域请求

作者: 增商 | 来源:发表于2020-03-08 13:24 被阅读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

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

    相关文章

      网友评论

          本文标题:跨域请求

          本文链接:https://www.haomeiwen.com/subject/dualdhtx.html