Form submission with AJAX

Without ever making your users leave the website, you can easily send the form using AJAX. We've provided a few examples of making HTTP requests from some of the most popular libraries.

Example using the Fetch Library

1 // https://github.com/github/fetch
2 fetch("https://justsignup.com/ajax/your@email.com", {
3 method: "POST",
4 headers: {
5 'Content-Type': 'application/json',
6 'Accept': 'application/json'
7 },
8 body: JSON.stringify({
9 name: "JustSignup",
10 message: "I'm from Kaywat.codes"
11 })
12 })
13 .then(response => response.json())
14 .then(data => console.log(data))
15 .catch(error => console.log(error));
fetch.js hosted with ❤ by GitHub view raw

Example using the Axios Library

1 // https://github.com/axios/axios
2 axios.defaults.headers.post['Content-Type'] = 'application/json';
3 axios.post('https://justsignup.com/ajax/your@email.com', {
4 name: "JustSignup",
5 message: "I'm from Kaywat.codes"
6 })
7 .then(response => console.log(response))
8 .catch(error => console.log(error));
axios.js hosted with ❤ by GitHub view raw

Example using the jQuery Library

1 // https://api.jquery.com/jQuery.ajax
2 $.ajax({
3 method: 'POST',
4 url: 'https://justsignup.com/ajax/your@email.com',
5 dataType: 'json',
6 accepts: 'application/json',
7 data: {
8 name: "JustSignup",
9 message: "I'm from Kaywat.codes"
10 },
11 success: (data) => console.log(data),
12 error: (err) => console.log(err)
13 });
jquery.js hosted with ❤ by GitHub view raw