我是后端代码的新手,我正在try 创建一个函数来响应JSON字符串.我现在有一个例子
function random(response) {
console.log("Request handler 'random was called.");
response.writeHead(200, {"Content-Type": "text/html"});
response.write("random numbers that should come in the form of json");
response.end();
}
这基本上只是打印字符串"应该以JSON形式出现的随机数".我想要它做的是用任意数字的JSON字符串进行响应.我需要换一种内容类型吗?这个函数是否应该将该值传递给另一个函数(比如客户端)?
谢谢你的帮助!