Why this doesn't work
$(document).on('click', '.title', function(){
let fn = 'abc';
$.post('common.php', {fn}, function(data) {
console.log(data);
});
});
common.php
if (isset($_POST['fn'])) {$_POST['fn']();}
$cols = '323';
function abc() {
global $db; // this works (db connection);
global $cols;
echo $cols; // doesn't work result is empty
echo '323'; // this works
}
There is no logic - some global variables work (for example $db connection) and some don't work.
Any help?
;after$dbif function is called using variable. Callabc()usingif (isset($_POST['fn'])) {$_POST['fn']();}Typo corrected.$colsdoesn't defined. But if you define variable before function call, it work correctly. 3v4l.org/8cUNjisset($_POST['fn'])is true.