我有一个表格显示ID,点击后我会得到ID。 然后我使用了Json并将其发送到editReport.php页面,我想要获取变量以查看我想编辑的报告。我可以在editReport页面上找到它的php变量吗?我已经使用JSON用PHP填充javascript变量,但无法找到将javascript转换为PHP的方法。
//Reports.PHP
function myFunction() {
$(".reportId").click(function () {
var selectedReportId = $(this).text();
//alert to test if gets ID from click
alert(selectedReportId);
selectedReportId = JSON.stringify(selectedReportId);
localStorage.setItem('selectedReportId', selectedReportId);
window.location = "editReport.php";
});
}
这是var发送到的页面。任何可能的方法将该变量放入PHP var
//editReports
<script type="text/javascript">
function myFunction() {
alert("hi");
var selectedReportId = localStorage.getItem('selectedReportId');
if (selectedReportId) selectedReportId = JSON.parse(selectedReportId);
alert(selectedReportId);
$.post('editReport.php', {variable: selectedReportId});
}
<?php
//make this variable populated from the javascript
$varID = $_POST['variable'];
echo "$varID";
?>
答案 0 :(得分:1)
您可以使用如下查询字符串:
window.location = "editReport.php?selectedReportId="+selectedReportId
然后在php中使用:
检索该变量 $selectedReportId = $_GET['selectedReportId'];
答案 1 :(得分:0)
如果您不想使用POST或GET,您还可以在editReport.php中执行以下操作:
In [284]:
((df['a'] > 5) & (df['b'] < 5)).astype(int)
Out[284]:
0 0
1 0
2 0
3 0
4 0
5 0
6 1
7 1
8 0
9 0
dtype: int32
这应该通过屏幕输出将其拉入PHP。
希望这有帮助!