[英]getting php session variable in js file
我有一个带有php if语句的php文件,该语句为mySQL表名生成php会话变量。 我需要访问该表的名称是一个javascript文件demo.js。 任何想法都很棒。
PHP代码片段:
$fcyclestartdate = $_POST['CycleStartDate'];
$fcycleenddate = $_POST['CycleEndDate'];
$_SESSION["paycycletable"] = "PCR_".str_replace("-", "", $fcyclestartdate)."_".str_replace("-", "", $fcycleenddate);
js文件代码Snip-it:
function DatabaseGrid()
{
this.editableGrid = new EditableGrid("demo", {//Variable table name must go where "demo" is
enableSort: true,
// define the number of row visible by page
pageSize: 50,
// Once the table is displayed, we update the paginator state
tableRendered: function() { updatePaginator(this); },
tableLoaded: function() { datagrid.initializeGrid(this); },
modelChanged: function(rowIndex, columnIndex, oldValue, newValue, row) {
updateCellValue(this, rowIndex, columnIndex, oldValue, newValue, row);
}
});
this.fetchGrid();
}
将表名称保存在JS全局空间中。
在您的PHP代码中:
echo "<script> paycycletable='" . $_SESSION["paycycletable"] . "'</script>";
现在,您可以在JS中的任何位置使用此变量
this.editableGrid = new EditableGrid(paycycletable, {...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.