Timeline for Is it possible to get the response from a form POST?
Current License: CC BY-SA 4.0
8 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Nov 9, 2021 at 3:37 | vote | accept | JMP | ||
Nov 6, 2021 at 18:46 | answer | added | 0Valt | timeline score: 2 | |
Nov 6, 2021 at 17:57 | comment | added | 0Valt |
I am mentioning Fetch API as it at least might ease the pain of having to resort to a submit event listener (as it is slightly less verbose than XMLHttpRequest ) either way to be able to both see the response and not reload the page. Unfortunately, there is little you can do if you want both being able to submit the form and see the response.
|
|
Nov 6, 2021 at 17:53 | comment | added | 0Valt |
Fetch API actually is much easier to use and is a way to go forward with asynchronous requests in JS, but the XMLHttpRequest is still useful when maintaining legacy code or writing one that is compatible with old browsers, so I am mostly asking that part out of curiosity. Fetch equivalent would be something like: fetch(url, { method: "POST", body: <body here, can be an instance of FormData in your case> })
|
|
Nov 6, 2021 at 17:51 | comment | added | 0Valt |
As for your specific problem, it is the way HTML forms work by default. If you want it to stop from reloading, you need to add a submit listener and prevent the default event action. Unfortunately, that will bring you back to square one of using either XMLHttpRequest or fetch . P.s. Sorry, forgot to send the draft
|
|
Nov 6, 2021 at 17:04 | comment | added | JMP | @OlegValter; I'm used to the simple syntax of XMLHttpRequest and the similar MSXML2.serverXMLHTTP in MS365, all my software uses it, and Fetch doesn't look at all easy, for example see developer.mozilla.org/en-US/docs/Web/API/Fetch_API/… | |
Nov 6, 2021 at 16:48 | comment | added | 0Valt |
Tangential question: is there any reason why you do not want to use the Fetch API in late 2021 and opted for XMLHttpRequest instead?
|
|
Nov 6, 2021 at 14:52 | history | asked | JMP | CC BY-SA 4.0 |