Help topics

Your forms

Sending with JavaScript

If your form is a React, Vue or Astro component, or you want to show a message without leaving the page, send the submission with fetch and ask for JSON back.

const res = await fetch("https://submits.dev/f/abcd1234", {
  method: "POST",
  headers: { "Content-Type": "application/json", "Accept": "application/json" },
  body: JSON.stringify({ email, message }),
});
const data = await res.json();
// { ok: true, message: "Submission received" }

The form URL accepts requests from any website, so you don't need to change any CORS settings. The body must be a JSON object. A list or a bare string gets a 422.

When you get JSON back

We answer with JSON instead of a redirect when any of these is true:

  • The Accept header asks for application/json.
  • The body is JSON.
  • The request sends X-Requested-With: XMLHttpRequest.

Errors come back as { "ok": false, "error": "..." } with a status code. Limits and responses lists every code.

Sending a FormData object

fetch with a FormData body works too. Add the Accept header so you get JSON instead of a redirect.