I am trying to send a variable with jquery to a php script now this is my first try after reading the documentation but it wont work. can anyone give me some advice ? I didn't realize the error in code. The variable I want to send is $id. I defined it with '1'
<?php
$id = '1';
?>
jquery part
<script>
$(document).ready(function() { // Anfang Dokument Ready Funktion
$("p").click(function () { // Anfang Klick Funktion
var id = $(this).html(); // Inhalt in Klickfunktion
// Beginn Ajax Segment mit Angabe von Typ Url Data und Div #ausgabe
$.ajax({
type: 'POST',
url: 'http://localhost/ajax.php',
data: 'id='+id',
success: function(data){
$('#ausgabe').html(data);
}
}); // Ende Ajax Segment
}); // Ende Klick Funktion
}); // Ende Dokument Ready Funktion
</script>
<div id="ausgabe"></div>
<p><button>Sende Variable</button></p>
The ajax.php
<?php
$id = $_POST['id'];
echo $id;
?>