when i press it the firebug console shows POST ajax/selection.php for one second then its empty again –
Aaaah, the page gets reloaded. You should listen to the submit
event of the <form>
, and be sure to call event.preventDefault()
inside the handler.
HTML:
<form action="ajax/selection.php" method="post" id="yourForm">
<input name="selectedPatient" type="text">
<input type="submit" value="Submit">
</form>
JS:
$('#yourForm').submit(function(event){
// this prevents the page from being reloaded
event.preventDefault();
$.post(
$(this).attr('action'), // gets action from the form itself
$(this).serialize() // serializes the whole form
).done(function(data){ // do your business here });
});