【发布时间】:2015-07-04 11:04:00
【问题描述】:
在这个Question我读到,在node.js中你可以像这样区分html请求和json请求:
app.get('/route', function (req, res) {
if (req.is('json')) res.json(data);
else if (req.is('html')) res.render('view', {});
else ...
});
现在我的问题是如何发出在节点服务器中被解释为 json 的请求?
因为我尝试使用 $.ajax 和 $.getJson 并在浏览器中输入,都是 html 请求。
这是我的要求
$.ajax({ type: 'GET', url: "/test", dataType:"json", success: function(data){log(data)}})
【问题讨论】:
-
您是否在 ajax 调用中设置了 datatype = json?
-
是的,我有,但没有任何区别
标签: javascript jquery json node.js