我有一个标签和一个下拉菜单,当下拉菜单更改时,标签会动态更改。所以我使用 ajax 来解决这个任务,但是如何将标签值传递给另一个文件 php 文件?我怎样才能发布它?
标签和下拉菜单;
<?php echo '<select name="type" id="category" onchange="changeOwner();">
<option value="Staf DC">Staf DC</option>
<option value="Admin">Admin</option>
</select></th>';
echo "<td align='center'><label id='own'></label></td>";
javascript;
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
function changeOwner()
{
var selname = $("#category option:selected").val();
$.ajax({ url: "new_getdata.php",
data: {"selname":selname},
type: 'post',
success: function(output) {
$("#own").html(output);
}
});
}
window.onload = changeOwner();
</script>
new_getdata.php
if (isset($_POST['selname'])) {
$selname = $_POST['selname'];
$query = "SELECT * FROM owner2 where type='$selname'";
$res = mysql_query($query);
while ($rows = mysql_fetch_assoc($res)) {
$name = $rows['owner'];
echo $name;
}
}
每次下拉菜单更改时,变量 $name 都会动态替换标签值。如何将标签值发送到另一个 php 文件?假设我想将其发布到 register.php