- Asynchronous JavaScript and XML
- Communicate with the backend (remember the JS weakness?)
- POST or GET?
- GET: select
- POST: insert, update, delete
- $.post, $.get, $.ajax
$.post( url, sendData, callback(data) {
});
- sendData is a JSON object
var sendData = {
id : 2,
action : 'delete'
};
- Store and retrieve data inside DOM
- Any data type, number, string, boolean, etc.
<div data-id="5">
<article data-author="Bilbo Baggins">
<section data-is-awesome="true">
- Set and get value with .data
$('article').data('author');
$('article').data('author', 'Frodo Baggins');
$.post('/add.php', sendData,
function(data) {
if( data.success ) {
$el.find('.counter')
.html(data.total);
}
}, 'json');
});