我有一个间隔检查,返回和意外的令牌错误。我每秒都在调用admin-ajax.php,而且我希望每次检查都得到一个+ 1的整数值。我已经检查了我用来从另一个函数传输的会话变量的输出,并且工作正常。我知道我已接近钉住这一点 - 只是在最后一道障碍失败了。任何帮助都会很棒。
Jquery post call函数是:
var cjd_interval = null;
function cjd_interval_checker(){
var cjd_email_fans_nonce = $("#cjd_email_nonce").val();
var data = {
'action': 'cjd_update_progress_bar',
nonce: 'cjd_email_nonce'
};
$.post(cjdAjax.ajaxurl, data, function(response) {
var result = jQuery.parseJSON(response);
console.log(result);
$("#cjd-progressbar").attr('value', result);
});
};
PHP函数是:
function cjd_update_progress_bar() {
/**
* Check Permissions
*/
if( current_user_can( 'manage_options' ) ) {
$count = $_SESSION['counter'];
echo json_encode( $count );
}
wp_die();
}
add_action( 'wp_ajax_nopriv_cjd_update_progress_bar', 'cjd_update_progress_bar' );
add_action( 'wp_ajax_cjd_update_progress_bar', 'cjd_update_progress_bar' );
答案 0 :(得分:0)
$.post(cjdAjax.ajaxurl, data, function(response) {
var result = jQuery.parseJSON(response);
console.log(response);
$("#cjd-progressbar").attr('value', response);
});
你输错了,你输入了结果而不是回复。
$("#cjd-progressbar").attr('value', response);
可以更改为:
$("#cjd-progressbar").val(response);