Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 前端仅接收参数为;";_Node.js_Reactjs_Express_Parameters_Fetch - Fatal编程技术网

Node.js 前端仅接收参数为;";

Node.js 前端仅接收参数为;";,node.js,reactjs,express,parameters,fetch,Node.js,Reactjs,Express,Parameters,Fetch,每当我请求时,不管我传递什么,它都会在服务器上显示{id:'t'} app.get("/get_test?:id", (req, res) => { console.log(req.params.id); res.send(req.params); }) // client side code fetch("/get_test?" + props.id) .then(res => res.json()) .then(


每当我请求时,不管我传递什么,它都会在服务器上显示{id:'t'}

app.get("/get_test?:id", (req, res) => {
    console.log(req.params.id);
    res.send(req.params);
})

// client side code    

fetch("/get_test?" + props.id)
.then(res => res.json())
.then(data => {console.log("Data from server: ",data)})
.catch(err => console.log(err))

如果要获取查询参数,只需使用query(而不是params)

或使用参数,但url将不同

app.get("/get_test/:id", (req, res) => {
    console.log(req.params.id);
    res.send(req.params);
})

如果要获取查询参数,只需使用query(而不是params)

或使用参数,但url将不同

app.get("/get_test/:id", (req, res) => {
    console.log(req.params.id);
    res.send(req.params);
})

您没有在url中指定查询参数名称

fetch("/get_test?id=" + props.id) // here 
.then(res => res.json())
.then(data => {console.log("Data from server: ",data)})
.catch(err => console.log(err))
而且,在服务器端,您不应该像这样形成get处理程序,因为您混合了路径参数和查询参数

app.get("/get_test", (req, res) => { // here do not use the ?:id
    console.log(req.query.id);
    res.send(req.query);
})

您没有在url中指定查询参数名称

fetch("/get_test?id=" + props.id) // here 
.then(res => res.json())
.then(data => {console.log("Data from server: ",data)})
.catch(err => console.log(err))
而且,在服务器端,您不应该像这样形成get处理程序,因为您混合了路径参数和查询参数

app.get("/get_test", (req, res) => { // here do not use the ?:id
    console.log(req.query.id);
    res.send(req.query);
})