คิดว่าcode client น่าจะผิดรบกวนช่วยผมหน่อยครับ
code server
โค้ด: เลือกทั้งหมด
const db = mysql.createConnection({
user: "root",
host: "localhost",
port: "3306",
password: "",
database: "chemicalsystem",
});
app.listen(3001, () => {
console.log("Yey, your server is running on port 3001");
});
app.get("/chemicalsgetlistbarcode/:ID_L", (req, res) => {
const chemical_Linfo = req.params.chemical_Linfo;
db.query("SELECT chemical_Lname , chemical_Lcode FROM chemical_list where ID_L= ?",[req.params.ID_L], (err, result) => {
if (err) {
console.log(err);s
} else {
res.send(result);
}
});
});
code client ไม่สามาร get data มาไว้ตรง label ได้
โค้ด: เลือกทั้งหมด
import React from "react";
import { useState } from "react";
import Axios from "axios";
export default function Dashboard() {
const [chemicalListbarcode, setChemicalListbarcode] = useState([]);
const getChemicalbarcode = (ID_L) => {
Axios.get(
`http://localhost:3001/chemicalsgetlistbarcode${ID_L}`
).then((response) => {
setChemicalListbarcode(response.data);
});
};
return (
<div>
<label className="form-label">Scan barcode:</label>
<div className="btn-toolbar mb-3">
<input
id="Scanbarcode"
autocomplete="off"
onChange={() => getChemicalbarcode()}
className="form-control"
type="text"
style={{ backgroundColor: "lightblue" }}
autoFocus
/>
</div>
<div class="col-md-3">
<label className="form-label">Chemical Code:</label>
{chemicalListbarcode.map((val) => {
return <label id="chemical_code">{val.chemical_Lcode}</label>;
})}
</div>
<div class="col-md-3">
<label class="form-label">Chemical Name:</label>
{chemicalListbarcode.map((val) => {
return <label id="chemical_name">{val.chemical_Lname}</label>;
})}
</div>
</div>