Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.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
Mysql 如何从数据库中获取特定的api?_Mysql_Node.js_Reactjs - Fatal编程技术网

Mysql 如何从数据库中获取特定的api?

Mysql 如何从数据库中获取特定的api?,mysql,node.js,reactjs,Mysql,Node.js,Reactjs,} 如何通过发送带有URL的所需ID从数据库中获取特定数据?您可以使用javascript中的格式字符串语法,并使用该语法将ID添加到URL字符串中 componentDidMount() { fetch("http://localhost:5000/customers/:id") .then((res) => res.json()) .then((info) => { this.setState({ info }); }) .then(

}


如何通过发送带有URL的所需ID从数据库中获取特定数据?

您可以使用javascript中的格式字符串语法,并使用该语法将ID添加到URL字符串中

 componentDidMount() {
fetch("http://localhost:5000/customers/:id")
  .then((res) => res.json())
  .then((info) => {
    this.setState({ info });
  })
  .then((err) => console.log(err));

例如,如果我在表单中使用ID登录,如何在单击“登录”时将表单ID添加到URL?
const id = 42
fetch(`http://localhost:5000/customers/${id}`)