Available on: All plans
You can use AJAX to submit your forms — this even works cross-origin. First create a new form in your dashboard. Then, in your form code, use an AJAX library to send your data as JSON. Be sure to set the Accept
header to application/json
so that the response comes back as JSON.
This example uses the Axios HTTP library.
axios({
url: 'https://formspree.io/f/YOUR_FORM_ID',
method: 'post',
headers: {
'Accept': 'application/json'
},
data: {
email: 'a.visitor@email.com',
message: "Hello!"
}
}).then((response) => { console.log(response); })
Here's the same example using jQuery. Note the dataType: "json"
property, it's required to set the Accept
header.
$.ajax({
url: "https://formspree.io/f/YOUR_FORM_ID",
method: "POST",
dataType: "json",
data: {
email: "a.visitor@email.com",
message: "Hello!"
}
});
If you're using React, check out our React Library.