I’ve got some Javascript which gets the HTML for a form from the server via an XMLHttpRequest, and displays the form on the page.
What I’d like to be able to do is extract the data which would be sent via POST if the form was submitted, then send it via another XHR. The tricky bit is that the form could contain different elements of different types.
Is there a way of doing this without having to inspect each element on the form, determine its type, manually extract the data based on the type, and build it all into a query string?
No, there isn’t, but there are prewritten libraries that have the code for that already written. e.g. jQuery serialize
Note that if you want to make a POST request, then the data should go in the request body, not the query string.