Her er et eksempel på, hvordan du skal udføre Ajax-anmodninger med jQuery/PHP/MySQL
JS
var postData = {
first_name: 'Foo',
last_name: 'Bar',
phone: '1-555-432-1234'
};
$.post('path/to/ajax/url.php', postData)
.done(function(response) {
alert("Data Loaded: " + response);
});
PHP
// Connect to MySQL
$dbh = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
// We want do some validation on the data so we can make a function called
// `validate()` if you want.
$data = validate($_POST);
$stmt = $dbh->('INSERT INTO my_table (first_name, last_name, phone)
VALUES (:first_name, :last_name, :phone)');
$stmt->execute($data);