前端请求

  • node 简单跨域
const express = require("express");

const app = express();

const port = 4000;

app.all('*', function (req, res, next) {
  res.header('Access-Control-Allow-Origin', '*');
  res.header('Access-Control-Allow-Headers', 'Content-Type');
  res.header('Access-Control-Allow-Methods', '*');
  res.header('Content-Type', 'application/json;charset=utf-8');
  next();
});

app.get("/", (req, res) => {
  console.log(112)
  res.json({
    code: "连接成功",
  });
});
app.listen(port);
  • 前端简单请求


  
    
    
    Document
  
  
  
  


你可能感兴趣的:(前端请求)