我一直在尝试让我的表单将其结果提交到 PHP 文件,然后对其进行查询并输出结果。我的 PHP 文件使用其查询以及使用标准 PHP $_GET 方法传递的变量,但尝试使用 Jquery AJAX 传递我正在努力的值。 任何帮助将不胜感激。 这是我目前所处的位置:
网页文件
<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>
我目前尝试的脚本插入页面顶部,我的PHP文件名为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>
谢谢
$('#form1').submit(function(e) {
e.preventDefault(); // stops form from submitting naturally
$.ajax({
data: $(this).serialize(),
//type: 'GET', //'GET' is default, set to 'POST' if you want.
url: '/details.php',
success: function(response) {
$('#result').html(response);
}
});
});