[英]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.