我想知道是否有人能就我的问题给我进一步的建议。我的插件的一部分存储了用于调试的日志文件。我已经使用jquery和wp\\u localise\\u脚本在我的管理页面的(div#log)中成功地显示了它们。我有一个删除这些日志的按钮,但我不确定如何处理。我觉得ajax可能会在这里派上用场,但不确定从哪里开始。
以下是我的代码的相关部分:
admin_enqueue_scripts (action)
$args = array(get_option(\'wow_tweets_log\'));//log files fetched from wp_options table
wp_enqueue_script(\'wow_tweet\');//registered earlier on with jQuery dependency
wp_localize_script(\'wow_tweet\', \'wow_vars\', $args);
Admin Page
<tr><th scope="row"><strong>Debugging</strong></th><td>
<div id="debug" class="button-primary">Debug</div><!--debug button shows logs-->
<div id="hide_debug" class="button-secondary">Hide</div><!--debug button hides logs-->
<div id="clear_log" class="button-secondary">Empty Log</div><!--Press to delete logs-->
</td></tr>
<tr><th scope="row"></th><td><div id="log"><!--Logs show here--></div></td></tr>
Javascript
jQuery(document).ready(function() {
var debug_show = jQuery(\'#log\').hide();//hides log by default
jQuery(\'#debug\').click(function(){//on click shows logs files in div#log
for (var i = 0, l = wow_vars.length; i < l; i++) {
var data = wow_vars[i];
}
jQuery(\'#log\').show().html(data);
});
jQuery(\'#hide_debug\').click(function()
{
debug_show.hide();
});
});
Action to clear log
function clear_log(){
delete_option(\'wow_tweets_log\');//am stuck on how to invoke this
/*die(); would go at the end if ajax used*/
}
add_action(\'clear_log\',\'clear_log\');
到目前为止,此脚本正在显示所有日志文件,现在我只需要在单击#clear\\u log时删除它们。我知道在init上插入do\\u操作将在页面加载后立即删除它们,这使得我的javascript毫无用处,所以我想唯一的选择是ajax!是否需要添加对wp\\u localize\\u script()的另一个引用?任何帮助都将不胜感激。