以下是我的问题,我在发送数据时出现错误
TypeError:res.json不是函数。
$client = new \GuzzleHttp\Client();
$response = $client->request('get', 'http://localhost/data', ['total' => ['total' => 15]);
我尝试了以下两种方法,但是它们似乎没有用。
exports.data= function(res,req){
return res.json({ result: 'success' });
};
exports.data= function(res,req){
res.json({ result: 'success' });
};
节点在端口3000上工作。
错误代码:TypeError:res.json不是函数或php页面 类型:GuzzleHttp \ Exception \ ServerException
消息:服务器错误:GET http:// localhost:3000 / data导致 500 Internal Server Error响应:TypeError:res.j(被截断...)
答案 0 :(得分:3)
回调方法中的第一个参数是req
,然后是其res
所以您的方法应该是
exports.data= function(req,res){
return res.json({ result: 'success' });
};
Or
exports.data= function(req,res){
res.json({ result: 'success' });
};
您已经交换了他们的positions
。这就是您收到错误消息的原因。