我有一个页面说,a.php。在页面中,单击按钮时,我调用了函数"sample"。
<script type="text/javascript">
function sample(id,no) {
jQuery.post('s.php', { ID: id, Number: no }, function(response) {
window.self.location='s.php'
});
}
</script>
<input name="" value="submit" type="button" onClick="return sample('5','10');">
我需要将值发布到 s.php。
我的上述代码可以吗?
请尝试
a.php
<form method="_POST" action="s.php">
<input name="id" value="5">
<input name="number" value="10">
<input name="" value="submit" type="button">
</form>
s.php
<?php
if(isset(id) && isset(number)) {
echo id = $_POST['id'];
echo number = $_POST['number'];
}
?>
您需要访问 $_POST 数组: http://php.net/manual/en/reserved.variables.post.php
数组键将与表单输入名称相同,因此 ID 和数字。
$id = $_POST['ID'];
$number = $_POST['Number'];
然后根据需要使用变量。此时要小心 SQL 注入(清理输入)。