How do you make an Ajax call in jQuery?
{ "status": "ok", "items": 3 }
<p>Page</p>
$.ajax({ url: 'data.json', dataType: 'json' })
.done(function (res) { console.log('Status: ' + res.status + ', items: ' + res.items); })
.fail(function () { console.log('Request failed'); });
Console output
Status: ok, items: 3
See jQuery Ajax.
Learn more about the similar topics:
| Tutorials |
|---|
| jQuery load() Method |
| jQuery Ajax: ajax(), get(), post() and getJSON() |
| jQuery Deferred, Promises and $.when() |
| Exercises & Assignments |
|---|
| Write jQuery code to load JSON data with Ajax and show it in a list |
| Write jQuery code to submit a form with Ajax |