FormData and JSON payloads, so you can post directly from the browser.
Browser requests receive a 303 redirect instead of JSON. When submitting with JavaScript, treat a 303 status as success or send the request from your server for a JSON response.
1
Build your form
Create a normal HTML form with
name attributes. JavaScript will serialize it.2
Submit with your preferred method
- Fetch
- XHR
- jQuery
redirect: 'manual' prevents the browser from following the redirect and running into CORS issues.If you need a JSON response, submit from your server (for example, an API route or server action) instead of the browser.