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 $.ajaxSetup() Example | 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; } #loadData { background: #2a73cc; color: #fff; border: none; padding: 10px 20px; cursor: pointer; margin-top: 10px; font-size: 16px; } #result { border: 1px solid #ccc; background: #fff; padding: 15px; margin-top: 20px; } #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 $.ajaxSetup() Example</h2> <p>This example uses <kbd>$.ajaxSetup()</kbd> to define global AJAX settings, including default URL, method, and timeout.</p> <button id="loadData">Load Data</button> <div id="loader"><span class="spinner"></span>Loading data, please wait...</div> <div id="result">Result will appear here.</div> <script> $(function() { // Global AJAX settings $.ajaxSetup({ url: 'json-data.php', type: 'GET', dataType: 'json', timeout: 5000 }); $('#loadData').on('click', function () { $('#loader').show(); $.ajax({ success: function (response) { $('#loader').hide(); $('#result').html( 'Name: ' + response.name + '<br>Email: ' + response.email + '<br>City: ' + response.city + '<br>Country: ' + response.country + '<br>Skills: ' + response.skills.join(', ') + '<br>Age: ' + response.profile.age + '<br>Member Since: ' + response.profile.member_since + '<br>Active: ' + (response.profile.active ? 'Yes' : 'No') ); }, error: function () { $('#loader').hide(); $('#result').html('Error loading data.'); } }); }); }); </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