There is something I'm missing, and I would like to understand why.
The CommentBox component has the onSubmit method and also the old fashion action method. When we have javascript enabled the route /api/client/ should receive 2 post request. One in Json format and one in html.
Normally e.preventDefault() will stop the execution of the server-side request.
In order to test I commented e.preventDefault() and with my surprise the comment is still added only once. I'm quite curious about why this happens.
So I thought that on server side when the first /api/comments POST is received the res.redirect trigger a page reloading and this probably kills all the ajax (client-side requests)..
In order to test that I put the res.redirect function inside a setTimeout of 3 sec. And know what? the comment is still not showing twice.. Is that the form submit that kills the ajax call?
Ok sorry I answered myself!
In the case js enabled, the server side code does not execute since the setState({author:"" etc}) is executed and the form submit on server side has empty values..
There is something I'm missing, and I would like to understand why.
The CommentBox component has the onSubmit method and also the old fashion action method. When we have javascript enabled the route /api/client/ should receive 2 post request. One in Json format and one in html.
Normally e.preventDefault() will stop the execution of the server-side request. In order to test I commented e.preventDefault() and with my surprise the comment is still added only once. I'm quite curious about why this happens.
So I thought that on server side when the first /api/comments POST is received the res.redirect trigger a page reloading and this probably kills all the ajax (client-side requests)..
In order to test that I put the res.redirect function inside a setTimeout of 3 sec. And know what? the comment is still not showing twice.. Is that the form submit that kills the ajax call?