diff --git a/csv-read2object/app/components/csv-reader.jsx b/csv-read2object/app/components/csv-reader.jsx index 4dfe38f..1828d2c 100644 --- a/csv-read2object/app/components/csv-reader.jsx +++ b/csv-read2object/app/components/csv-reader.jsx @@ -1,5 +1,6 @@ import React, { useState } from "react"; import Papa from "papaparse"; +import axios from 'axios'; const allowedExtensions = ["csv"]; @@ -24,6 +25,16 @@ const CsvReader = () => { } } }; + const post = async (requestBody) => { + console.log('post() start...'); + console.log('post() requestBody: ' + JSON.stringify(requestBody)); + console.log('post() before post'); + /*If you pass a JavaScript object as the 2nd parameter to the axios.post() function, Axios will automatically serialize the object to JSON for you. Axios will also set the Content-Type header to 'application/json', so web frameworks like Express can automatically parse it.*/ + const data = await axios.post('http://localhost:3000/', requestBody).then(res => res.data); + console.log('post() after post'); + console.log('post() json data: ' + JSON.stringify(data)); + console.log('post() done.'); + }; const handleParse = () => { console.log('handleParse() start ...'); if (!file) { @@ -42,11 +53,17 @@ const CsvReader = () => { console.log('updateData() start...'); let data = result.data; setData(data); + post(data); console.log('updateData() done.'); }; return(