Wednesday 23 May 2018

Why is this throwing a type error?

So I have an api call from react that is throwing the error:TypeError: Converting circular structure to JSONSo I have this code in the react file:handleSubmit = (event) =>{event.preventDefault();//Get the valueslet name = event.target.name.value;let importance = event.target.importance.value;let desc = event.target.desc.value;let img = event.target.img.value;let video = event.target.video.value;let url = event.target.url.value;let formats = [];let types = [];{Object.keys(this.state.formatsList).map(item => {if(document.getElementById(item).checked){formats.push(document.getElementById(item));}})}{Object.keys(this.state.typesList).map(item => {if(document.getElementById(item).checked){formats.push(document.getElementById(item));}})}api.addProject(name, importance, desc, img, video, url, formats, types).then(console.log(name+" has been added.")).catch(console.error);}Then this in the react api file:export const addProject = (name, importance, desc, imgs, video, url, formats, types) => {return axios.post('api/addProject', {name: name,importance: importance,description: desc,images: imgs,video: video,url: url,formats: formats,types: types})}Then this in the site apirouter.post('/addProject', (req, res) => {const name= req.body.name;const importance= req.body.importance;const description= req.body.desc;const images= req.body.img;const video= req.body.video;const url= req.body.url;const formats= req.body.formats;const types= req.body.types;// validation ...mdb.collection('projects').insertOne({ name: name, importance: importance, description: description, images: images, video: video, url: url, formats: formats,types: types}).catch(error => {console.error(error);res.status(404).send('Bad Request');});});I'm totally lost on this, thanks for any help!

Submitted May 23, 2018 at 03:24PM by thelynched

No comments:

Post a Comment