Answer the question
In order to leave comments, you need to log in
How to work with mySQL on node.js?
Good afternoon, tell me how to write data to the database from the html form / fields by clicking on the button. wrote a simple application on node.js & express. connected to the database, did not do a lot of routing, set up work with the database, update / delete / add records, send requests via Postman and everything works. But there is no understanding how to organize work with the database, through the form and how to process data correctly, how to separate files. I tried to do it through the onclick event but nothing comes out, tell me where you can read about this or an example. I can post the project if needed.
Answer the question
In order to leave comments, you need to log in
Your project is divided canonically into 2 parts fe/be, fe works directly in the browser interpreter, and an object of type document or window is the browser entity. While be works in the nodejs environment and do not have access to the browser (in your version and solution of the problem), the connection between these entities is xmlhttprequest in your case it is json (rest) you need to send a request to BE with Fe
example -
var xhr = new XMLHttpRequest();
var params = 'name=' + encodeURIComponent(name) +
'&surname=' + encodeURIComponent(surname);
xhr.open("GET", '/submit?' + params, true);
xhr.onreadystatechange = ...;
xhr.send();
In general, it is customary to show the code in such cases.
If everything goes through postman, but not from the browser, then the problem is in the client side. For example, if the address (url) of the client part is at least somehow different from the server part, for example, the port is different, then CORS will be triggered, and the server needs to send the appropriate headers so that the requests go through, or proxy the requests with webpack.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question