Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
// Global auth header $.ajaxSetup({ headers : { 'Authorization': 'Bearer ' + localStorage.getItem('token') }, contentType: 'application/json', dataType : 'json' }); // CREATE $.ajax({ url: '/api/posts', method: 'POST', data: JSON.stringify({ title: 'Hello', body: 'World' }) }); // READ $.ajax({ url: '/api/posts/42', method: 'GET' }) .done(function (post) { console.log(post.title); }); // UPDATE $.ajax({ url: '/api/posts/42', method: 'PUT', data: JSON.stringify({ title: 'Updated Title' }) }); // DELETE $.ajax({ url: '/api/posts/42', method: 'DELETE' }) .done(function () { $('#post-42').remove(); });
Result
Open