Each shorthand returns the same Promise as $.ajax(). For $.get() and $.getJSON(), an object in the second argument becomes the query string; for $.post() it becomes an application/x-www-form-urlencoded body. A callback in the last position still works for older code.
View the source for this demo
<div class="row">
<button type="button" id="fs-load">Load team ($.getJSON)</button>
<button type="button" id="fs-sort">Sort by commits</button>
<button type="button" id="fs-quote">New quote ($.get)</button>
</div>
<div class="team" id="fs-team" aria-live="polite"></div>
<p id="fs-q" style="margin-top:14px;min-height:1.6em" aria-live="polite"></p>let team = [];
const render = () => $('#fs-team').html(team.map(u =>
'<div class="p"><b>' + $.escape(u.name) + '</b><small>' + $.escape(u.role) + ' · ' + u.commits + ' commits</small></div>').join(''));
$('#fs-load').on('click', async () => {
team = await $.getJSON('/api/users.json');
render();
$.from('#fs-team .p', { y: 14, opacity: 0, duration: .3, stagger: .06 });
});
$('#fs-sort').on('click', () => {
team.sort((a, b) => b.commits - a.commits);
render();
});
$('#fs-quote').on('click', async () => {
const n = 1 + Math.floor(Math.random() * 5);
$('#fs-q').html(await $.get('/api/quotes/' + n + '.html'));
});More examples
Shorthands
const users = await $.getJSON('/api/users', { team: 'core' }); // ?team=core
const html = await $.get('/partials/sidebar.html');
await $.post('/api/subscribe', { email });
$.get('/api/ping', data => console.log(data)); // callback styleAPI
GET shorthand; data becomes the query string.
POST shorthand (urlencoded body by default).
Reference: $.post() →Migrating
$.getScript() is not included — use a dynamic import() or a script element.Related features
AJAX with $.ajax
jQuery's $.ajax rebuilt on fetch: native Promises and async/await, JSON bodies, headers, timeouts with auto-abort, plus success/error callbacks and .done/.fail for migration..
Open →CoreLoading HTML fragments
Fetch a page and insert only the fragment you need with $(el).load("/page.html #section") — the classic jQuery partial-loading pattern on fetch..
Open →CoreForms & serialization
Turn forms into query strings or plain objects with serialize() and serializeObject(), then submit them with $.post — or declaratively with kj-post..
Open →