初學node,如何編寫數據接口,用以ajax交互呢?求demo或教程
node怎么編寫數據接口?
慕哥9229398
2018-09-06 14:31:05
TA貢獻1995條經驗 獲得超2個贊
可以看看Express
或者koa
直接寫nodejs
的話的node
下面的代碼,ajax
中的dataType
修改成text
,就能請求到
const http = require('http');const hostname = '127.0.0.1';const port = 1337; http.createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Hello World\n'); }).listen(port, hostname, () => { console.log(`Server running at http://${hostname}:${port}/`); });
舉報