-
案例目标:实现GET的主要属性为req.method,并且生成随机数
- 使用nodejs,实现一个Ajax的get请求方式
- 将lib里的data.json文件请求获取出来
- data里面的数据为
{ "success":[ { "data": "你赢了", "message":"请求成功", "code": "200" } ], "fail":[ { "data": "你输了", "message":"请求失败", "code": "200" } ] }
-
案例准备
-
-
案例代码
// 1.定义核心模块 http fs path const http = require('http') const fs = require('fs') const path = require('path') // 2.创建服务 const server = http.createServer((req, res) => { // 2.1 如果url地址为/getList 执行代码