我试图获得一个ajax调用来更新现有页面上的一个表(max),但它似乎不起作用。我认为问题出在函数的第一个页面中,因为下一个页面甚至没有得到我传递的参数。html表格(max)也在这个页面上。此页面中是否缺少某些内容?或者不正确地传递参数?这是我在初始页面上的脚本:
<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;
发布于 2020-03-13 16:52:38
看起来您传递的是Button的值,而不是文本输入。我会尝试像这样的东西。
<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>
https://stackoverflow.com/questions/60674237
复制相似问题