jquery - Wordpress AJAX request always return 0 -
i'm developing wordpress theme , in frontend need show information when user hovers on post preview. use ajax retrieve needed information instead of loading data each post, ajax queries return 0.
this excerpt of functions.php:
add_action( 'wp_ajax_nopriv_pgsc_ajax_get_supporters', 'pgsc_ajax_get_supporters' ); add_action( 'wp_ajax_pgsc_ajax_get_supportes', 'pgsc_ajax_get_supporters' ); function pgsc_ajax_get_supporters() { $politicianid = $_post['postid']; $field = get_field_object('lista', $postid); $values = get_field("lista", $postid); $lists = array(); foreach($values $val) { $listname = $field["choices"][$val]; $logo = get_field("logo", $val)["sizes"]["thumbnail"]; $lists[$listname] = array("permalink" => get_post_permalink($val), "logo" => $logo); } wp_reset_query(); echo json_encode($lists); wp_die(); }
and ajax call javascript:
function open_supporter_bar(postid, barid) { var bar = "#bar_" + barid; jquery(bar).hide("slow"); jquery(bar).html(""); jquery.ajax({ url : pgsc.ajaxurl, type : "post", data : { action : "pgsc_ajax_get_supporters", postid : postid }, success : function(result) { alert(result); html = compose_supporter_list(result); jquery(bar).html(html); jquery(bar).show("slow"); }, error : function(error) { alert("check error log!"); } }); }
i've tried replacing wp_die()
die()
result same
you have misspelled function on action hook.
add_action( 'wp_ajax_pgsc_ajax_get_supportes', 'pgsc_ajax_get_supporters' );
should be:
add_action( 'wp_ajax_pgsc_ajax_get_supporters', 'pgsc_ajax_get_supporters' );
Comments
Post a Comment