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 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测