在js文件中获取php会话变量

时间:2015-10-21 19:36:33

标签: javascript php mysql editablegrid

我有一个带有php if语句的php文件,它为mySQL表名生成一个php会话变量。我需要访问这个表名是一个javascript文件demo.js.任何想法都会很棒。

PHP Code Snip-it:

$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();   
}

1 个答案:

答案 0 :(得分:0)

将表名保存在JS全局空间中。

在你的PHP代码中:

echo "<script> paycycletable='" . $_SESSION["paycycletable"] . "'</script>";

现在你在JS中的任何地方都有这个变量

this.editableGrid = new EditableGrid(paycycletable, {...