【发布时间】:2011-08-19 01:15:10
【问题描述】:
我是后端代码的新手,我正在尝试创建一个函数来响应我的 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 字符串响应。我需要放置不同的内容类型吗?这个函数应该将该值传递给客户端的另一个人吗?
感谢您的帮助!
【问题讨论】:
-
res.json({"Key": "Value"});
标签: javascript node.js