admin管理员组文章数量:1130349
I'm trying to select a column from database like so:
global $wpdb;
$results = $wpdb->get_col("SELECT start_time FROM admin_form_entry");
$start = $results[0];
Then, I send data to external javascript file:
function load_js_assets() {
if( is_page( 13 ) ) {
wp_enqueue_script('my-js', get_template_directory_uri() . '/testrun.js');
wp_localize_script( 'my-js', 'passedObject', array(
'start' => $start
)
);
}
}
add_action('wp_footer', 'load_js_assets');
And in the Javascript file the passedObject is always null!
var start = passedObject.start;
console.log("start >>> ", start);
I'm trying to select a column from database like so:
global $wpdb;
$results = $wpdb->get_col("SELECT start_time FROM admin_form_entry");
$start = $results[0];
Then, I send data to external javascript file:
function load_js_assets() {
if( is_page( 13 ) ) {
wp_enqueue_script('my-js', get_template_directory_uri() . '/testrun.js');
wp_localize_script( 'my-js', 'passedObject', array(
'start' => $start
)
);
}
}
add_action('wp_footer', 'load_js_assets');
And in the Javascript file the passedObject is always null!
var start = passedObject.start;
console.log("start >>> ", start);
本文标签: How to retrieve data from databasethen pass it to Javascript
版权声明:本文标题:How to retrieve data from database, then pass it to Javascript? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749114435a2317947.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论