如何解决将参数传递给PHP,不带形式
我有一个像这样的数据库。
den_j = fig.add_subplot(grid[j//6,j % 6],sharex=ax_main,sharey=ax_main)
# Draw the density plot
sns.distplot(layer_list,hist = False,kde = True,kde_kws = {'linewidth': 2},color=color,ax=den_j)
# ^^^^^^^^
在我的页面上,我得到上面的所有团队1的名称,在下面得到所有的团队2的名称。它读取所有播放器名称,并为每个播放器创建带有onclick事件的HTML元素。当我单击一个元素时,我会得到该元素的文本...
+------------+------+
| playername | team |
+------------+------+
| John | 1 |
| Tim | 2 |
| ... | ... |
我有一个PHP文件 change.php ,该文件在数据库中查找传递的名称,然后将团队从1更改为2或以其他方式进行更改。 (SQL查询在数据库中可以正常运行)
<?php include_once 'connection.php';?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Dashboard</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.js"></script>
</head>
<body>
<?php
$sql = "SELECT * FROM teams WHERE team = 1;";
$result = mysqli_query($conn,$sql);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck > 0) {
while ($row = mysqli_fetch_assoc($result)) {
echo "<button href='#' onclick='clickfunction(this)'>".$row['playername']."</button>";
}
}
?>
<?php
$sql = "SELECT * FROM teams WHERE team = 2;";
$result = mysqli_query($conn,$sql);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck > 0) {
while ($row = mysqli_fetch_assoc($result)) {
echo "<button href='#' onclick='clickfunction(this)'>".$row['playername']."</button>";
}
}
?>
<script>
function clickfunc(obj) {
var playername = $(obj).text();
**// SOME CODE TO PASS playername TO change.php**
}
</script>
</body>
</html>
问题: 现在,我遇到了一个我不知道该怎么做的问题,当我单击一个元素并读出文本时,将该文本作为参数发送到 chance.php 文件,以便PHP文件可以使用它。
例如:如果我单击John,则将文本“ John”作为参数发送到 chance.php 并在那里进行处理。结果就是,如果约翰在上方,那么他现在就在下方。或相反。
解决方法
因为您正在使用$_GET
获取值,所以只需使用javascript change.php
将页面重定向到window.location
并将参数放在URL中即可。
function clickfunc(obj) {
var playername = $(obj).text();
window.location = "change.php?playername=" + playername
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。