首先我在app.js中允许了所有请求
// 允许所有的请求形式 app.use(function(req, res, next) { res.header("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); next(); });
Express封装了GET请求,使请求更加简易
var express = require(‘express‘); var router = express.Router(); /* GET loves listing. */ router.get(‘/‘, function(req, res, next) { // 获取参数 var query = req.query; console.log("get请求:参数", query); res.send(‘hello,world‘); });