You need to specify the key of the data:
data: { 'id': id }
Also there are syntax errors in your snippet:
function getdata(id){
alert(id);
$.ajax({
type: "POST",
url: "activations.php",
data: {
'id': id // < no need for semi-colon, properties are key->value based, 'key': value
}
}); // << no closing bracket and semi-colon
} // << close your function
So you can access it in your activations.php:
$_POST["id"]
Always check if it is isset or not:
if (isset($_POST["id"])) $id = $_POST["id"]; else exit;
Answering OP's particular questions:
You need to open a PDO connection to your SQL server (example with MySQL)
if (isset($_POST["id"])) $id = $_POST["id"]; else exit;
$db = new PDO('mysql:host=localhost;dbname=yourdb;charset=utf8',
'username',
'password'); // Open a connection to your database
$q = $db->prepare("SELECT * FROM achievements WHERE id=?"); // Get all achievements where id=$id
$q->execute(array($id)); // Run the query
$rows = $q->fetchAll(); // Fetch the query, associated array
echo json_encode($rows); // Convert the $rows to json, so javascript can read it
You will have to set the datatype of your ajax request to JSON or parse the data on your own with $.parseJSON(data);
You can use the returned data with adding a success function to your ajax:
function getdata(id){
alert(id);
$.ajax({
type: "POST",
url: "activations.php",
data: {
'id': id // < no need for semi-colon, properties are key->value based, 'key': value
},
success: function(data) {
var achievements = $.parseJSON(data);
// use achievements variable
}
}); // << no closing bracket and semi-colon
} // << close your function