【发布时间】:2015-10-21 19:36:32
【问题描述】:
我有一个带有 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 执行,可能只是更改扩展名,然后在 JS 中使用
<?php echo $_SESSION["paycycletable"]; ?>而不是演示。 -
由于调用了js文件中的js函数,这个不起作用。
-
这没有任何意义......
-
如果文件无法更改为 php 文件,那么据我所知,您唯一的选择仍然是使用 ajax 加载会话值。
-
如果安全性不高,您可能需要设置
$_COOKIE而不是$_SESSION。然后 JS 可以从 cookie 的后缀中读取。
标签: javascript php mysql editablegrid