For the most common HTTP operations jQuery provides the convenience methods $.get() and $.post(), which require far less configuration than the full $.ajax() call while still returning a jqXHR promise.
$.get()
$.get(url, data, callback, dataType) performs a GET request. The data object is serialised to a query string and appended to the URL. Use it to fetch resources, search results, or filtered lists from a REST API.
$.post()
$.post(url, data, callback, dataType) sends data in the request body as application/x-www-form-urlencoded. Use it to submit forms, create resources, or trigger server-side actions.
- Both methods return a
jqXHRobject for promise chaining - Pass
'json'as the last argument to auto-parse the response - Query string parameters are URL-encoded automatically
Because GET requests are cached by browsers and appear in server logs, never use them to send sensitive data like passwords. Always use POST (or PUT/PATCH/DELETE via $.ajax()) for mutations.