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.
| 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)); |
| 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)); |
| 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 | }); |