Try It Editor
Tip: Press
Ctrl/⌘ + Enter
to Run
▶ Run
Reset
Copy
Download
Code
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Submit with AJAX (serialize)</title> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> </head> <body> <form id="f"> <input name="name" placeholder="Name" required> <input name="email" placeholder="Email" type="email" required> <button type="submit">Send</button> </form> <pre id="out"></pre> <script> $("#f").on("submit", function(e){ e.preventDefault(); var data = $(this).serialize(); // Demo endpoint echoes data $.post("https://httpbin.org/post", data) .done(function(resp){ $("#out").text(JSON.stringify(resp, null, 2)); }) .fail(function(){ $("#out").text("Network/CORS error in demo."); }); }); </script> </body> </html>
Output