Friday, 15 March 2019

axios form data post request to mysql model

Hi i'm trying to implement a basic backend REST API and ORM for the MVC model. Im using a React form and axios to handle http request from the user. I can get the form data correctly but when I post to the back end I get an error in the console.for now / testing , I don't have the model controller mutate the database object. it just prints hello to console.Im not sure if this is how you do it but I have the back end listening on port 5000 and the front end React running on 3000.My axios post(..) call looks like axios.post('http:/localhost:5000/newlisting' , { title: this.state.post.title, price: this.state.post.price, address: this.state.post.address, zip: this.state.post.zip, description: this.state.post.description })  then on the backend I just have a route in the app.js app.use('/newlisting',listingRouter);  and then the router in the listingrouter.js exports the router router.route('/').post(listingController.create);  I tested the router for get method router.route('/').method(listingController.create); and it works when I manually put the url into the browser.my console errors: Origin http://localhost:3000 is not allowed by Access-Control-Allow-Origin XMLHttpRequest cannot load http://localhost:5000/newlisting due to access control checks. Failed to load resource: Origin http://localhost:3000 is not allowed by Access-Control-Allow-Origin. I have no idea as I am pretty much completely new to web applications , I've only used REST APIs and created and edited simple MVC models with Rails generator (which I find so much easier than any implementation in nodejs) + this is my first time using a UI framework.

Submitted March 15, 2019 at 04:22PM by horrofan

No comments:

Post a Comment