I’ve been trying to get my form to submit its results to a PHP file, which are then queried and results outputted. My PHP file works with its query with variables passed with a standard PHP $_GET method but trying to work it with Jquery AJAX passing the values I’m struggling. Any help would be greatly appreciated. Here is what I’m currently at:
HTML File
<div id="content">
<div id="options">
<form id="form1">
<table>
<tr>
<td>Date:</td>
<td><input name="date" type="text" id="datepicker" /></td>
</tr>
<tr>
<td>Size:</td>
<td><input name="size" type="text" /></td>
</tr>
<tr>
<td colspan="2"><input name="submit" type="submit" value="Submit"/></td>
</tr>
</table>
</form>
</div>
<div id="result"> </div>
</div>
My current attempt at my script inserted at the top of the page with my PHP file named details.php.
<script>
$('#form1').submit(function() {
$.ajax({
data: $(this).serialize(),
type: $(this).attr('GET'),
url: $(this).attr('details.php'),
success: function(response) {
$('#result').html(response);
}
});
return false; // cancel original event to prevent form submitting
});
</script>
Thanks
1 Answer