window.onload = function() {
let name = <?= $this->session->userdata('username') ?>;
console.log(name)
}
1:534 Uncaught ReferenceError: ken is not defined at window.onload (1:534:20)
在error 上顯示名字is not defined,
但如果把username轉換成id就沒有error
let name = <?= $this->session->userdata('id') ?>;
因為是字串
要記得加上單引號
不然JS會以為是一個變數
window.onload = function() {
let name = '<?= $this->session->userdata('username') ?>';
console.log(name)
}