weixin_33705053 2015-07-24 19:38 采纳率: 0%
浏览 29

Wordpress Ajax响应0

I'm searching for an answer here for hours, and I can't find what's wrong with my code... my wordpress ajax keeps responding "0" no matter what I do... Here's the code:

header.php file:

wp_enqueue_script('js_'.$__page, NEVAL_ASSETS."js/js_course_{$__page}.js", array("jquery"));

js_course_all.js File:

var filter = jQuery("#input_filter").val()+"%";

var data = {
    "action": "course_showall_refresh",
    "data": {
        "sort": _sorting.col,
        "sort_dir": (_sorting.dir) ? 'asc':'desc',
        "filter": filter
    }
};

jQuery.post(ajaxurl, data, function(response){
    alert(response);
});

view .php file:

function refresh(){
    echo 'ajax_response';
    die();
}
add_action("wp_ajax_course_showall_refresh", "refresh");
add_action("wp_ajax_nopriv_course_showall_refresh", "refresh");

The .JS is being correctly imported (the alert goes off with a "0" answer, other functions (UI functions) work correctly.

  • 写回答

2条回答 默认 最新

  • weixin_33720452 2015-07-24 19:43
    关注

    Try doing this. It might solve your problem.

    jQuery.post(ajaxurl, data, function(response){
        alert(response);
    }, 'text');
    
    评论

报告相同问题?