-1

我有一个页面说,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。

我上面的代码可以吗?

4

2 回答 2

0

您需要访问 $_POST 数组: http: //php.net/manual/en/reserved.variables.post.php

数组键将与表单输入名称相同,即 ID 和 Number。

$id = $_POST['ID'];
$number = $_POST['Number'];

然后根据需要使用变量。此时要小心 SQL 注入(清理输入)。

于 2013-09-30T10:52:12.303 回答
0

请试试

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'];
}
?>
于 2013-09-30T10:47:41.860 回答