我正在尝试通过ajax调用来更新现有页面上的表(max),但它似乎没有用。我认为问题出在函数的第一页,因为下一页甚至没有获取我要传递的参数。 html表(最大值)也在此页面上。此页面上缺少什么吗?还是错误地传递了参数?这是我在初始页面上拥有的脚本:
<a name='top'></a>
<form action="pool.php">
Enter ID: <input type="text" name="clientid" id="txclientid">
<input type="button" name="btclientid" value="Submit">
</form>
<script>
$('#btclientid').click(function(){
$.post('pool.php',{clientid : $(this).val()}, function(response){
$(max).html(response);
});
});
</script>
这是在pool.php页面上,在该页面上,我抓取了参数以传递给它运行的查询(但似乎并没有达到目的):
$clientid = isset($_POST['clientid']) ? $_POST['clientid'] : NULL;
答案 0 :(得分:2)
似乎您正在传递按钮的值,而不是文本输入。我会尝试这样的事情...
<a name='top'></a>
<form action="pool.php" method="post" enctype="multipart/form-data">
Enter ID: <input type="text" name="clientid" id="txclientid">
<input type="button" name="btclientid" value="Submit">
</form>
<script>
$('#btclientid').click(function(){
$.post('pool.php',{clientid : $('#txclientid').val()}, function(response){
$(max).html(response);
});
});
</script>
我会尝试这样的事情:
<a name='top'></a>
<form action="pool.php" name="poolName" id="poolId" method="post" enctype="multipart/form-data">
Enter ID: <input type="text" name="clientid" id="txclientid">
<input type="button" name="btclientid" value="Submit">
</form>
<script>
$(document).ready(function () {
$('#btclientid').click(function(){
$( "#poolId" ).submit
});
});
$( "#poolId" ).submit(function( event ) {
// Stop form from leaving page
event.preventDefault();
//Gather Form Info/set variables
var form = $(this);
var url = form.attr('action');
//Post the form with Ajax
$.ajax({
type: "POST",
url: url,
data: form.serialize(), // serializes the form's elements.
success: function(data)
{
//What to do on success
$(max).html(data);
}
else{
//What to do on failure (error messages etc....)
}
}
});
return;
}
});
});
</script>