dpq755012465 2015-02-28 21:10
浏览 47
已采纳

Jquery意外令牌<

I have an interval check thats returning and unexpected token error. I'm doing a call to admin-ajax.php every second and I'm expecting to get an integer value + 1 on each check. I've checked the output of the session variable that I'm using to transfer across from another function and that works fine. I know I'm close to nailing this - just failing at the last hurdle. Any help would be great.

Jquery post call function is:

 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);
            });

        };

And the PHP function is:

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' );
  • 写回答

1条回答 默认 最新

  • dongmin3754 2015-02-28 21:14
    关注
    $.post(cjdAjax.ajaxurl, data, function(response) {
        var result = jQuery.parseJSON(response);
        console.log(response);
        $("#cjd-progressbar").attr('value', response);
    });
    

    You've made a typo, you've typed result insteaf of response.

        $("#cjd-progressbar").attr('value', response);
    

    This can be changed to:

        $("#cjd-progressbar").val(response);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输