Codelab Editor
Free Online HTML Editor
Run
Learn jQuery
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <title>jQuery AJAX Event - ajaxSend Method() | TutsInsider</title> <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script> <style> body { font-family: Arial, sans-serif; background: #f9f9f9; padding: 10px; } h2 { color: #2a73cc; } #submitForm { background: #2a73cc; color: #fff; border: none; padding: 10px 20px; cursor: pointer; margin-top: 10px; font-size: 16px; } #response { border: 1px solid #ccc; background: #fff; padding: 15px; margin-top: 20px; } #sendBox { display: none; margin-top: 20px; padding: 15px; background: #fffbe6; border: 1px solid #f0c14b; color: #b58900; font-weight: bold; } #loader { display: none; margin-top: 20px; padding: 15px; background: #e8f0fe; border: 1px solid #ccc; color: #2a73cc; font-weight: bold; text-align: center; } .spinner { display: inline-block; width: 24px; height: 24px; border: 3px solid #2a73cc; border-top: 3px solid transparent; border-radius: 50%; animation: spin 1s linear infinite; margin-right: 10px; vertical-align: middle; } @keyframes spin { to { transform: rotate(360deg); } } </style> </head> <body> <h2>jQuery AJAX Event - ajaxSend Method()</h2> <p>This example uses <kbd>ajaxSend</kbd> to notify just before the AJAX request is sent to the server.</p> <form id="userForm"> <label>Name: <input type="text" name="name" /></label><br><br> <label>Email: <input type="email" name="email" /></label><br><br> <label>City: <input type="text" name="city" /></label><br><br> <button type="submit" id="submitForm">Submit</button> </form> <div id="loader"><span class="spinner"></span>Submitting data, please wait...</div> <div id="sendBox">AJAX request is about to be sent...</div> <div id="response">Server response will appear here.</div> <script> $(function () { // Show loader when AJAX starts $(document).ajaxStart(function () { $('#loader').show(); }); // Hide loader when all AJAX calls complete $(document).ajaxStop(function () { $('#loader').hide(); }); // Show message just before AJAX request is sent $(document).ajaxSend(function () { $('#sendBox').show().delay(2000).fadeOut(); }); // Form submission $('#userForm').on('submit', function (e) { e.preventDefault(); const formData = $(this).serialize(); $.ajax({ url: 'jquery-serialize.php', type: 'POST', data: formData, success: function (response) { $('#response').html(response); }, error: function () { $('#response').html('Error submitting form.'); } }); }); }); </script> </body> </html>
Editor Commands
Ctrl
F
Find
Ctrl
G
Find Next
Ctrl
⇧
G
Find Previous
Ctrl
⇧
F
Find & Replace
Ctrl
]
Indent Code Right
Ctrl
[
Indent Code Left
⇧
Tab
Auto Indent Code
Ctrl
/
Line Comment
Ctrl
Alt
/
Block Comment
TutsInsider Actions
Alt
S
Run Code
Ctrl
C
Copy Editor Code
Ctrl
A
Select All Editor Code
Ctrl
S
Save/Download
Ctrl
Alt
X
Rotate
Ctrl
Alt
T
Switch Theme
Ctrl
⇧
C
Open Console
Esc
Close Console