dtqjbbr5283 2016-03-02 11:59
浏览 58
已采纳

Wordpress AJAX调用响应0

I'm tryng to set up a panel, this one enter image description here

The menu on the top calls different ajax functions in order to display a thumb. Clicking on the thumb you can see the details in the last box of the panel.

I have this php functions

function GetPostPartner(){
$catPartner = "loop_pb_partner";
get_template_part($catPartner);
wp_die();
}
add_action('wp_ajax_nopriv_GetPostPartner', 'GetPostPartner');

function GetPostEnte(){
$catEnte = "loop_pb_ente";
get_template_part($catEnte);
wp_die();
}
add_action('wp_ajax_nopriv_GetPostEnte', 'GetPostEnte');

function GetPostColl(){
$catColl = "loop_pb_coll";
get_template_part($catColl);
wp_die();
}
add_action('wp_ajax_nopriv_GetPostColl', 'GetPostColl');

function GetPostMedia(){
$catMedia = "loop_pb_media";
get_template_part($catMedia);
wp_die();
}
add_action('wp_ajax_nopriv_GetPostMedia', 'GetPostMedia');

function GetPostDetails(){
$pb_details = $_POST['postURL'];
get_template_part($pb_details);
wp_die();
}
add_action('wp_ajax_nopriv_GetPostDetails', 'GetPostDetails');

And those are called by these ajax functions

$(document).delegate('h4.homus-partners-global-ajax[data-pb-               cat*=pb_partner]', 'click', function(event) {
event.preventDefault();
var pb_cat = "pb_partner";
var data = {
    'action': 'GetPostPartner',
    catURL : "loop_"+ pb_cat,
};
$.post(ajaxURL, data, function(response) {
    $( 'ul.homus-partners-section-slide' ).html(response);
});

});

$(document).delegate('h4.homus-partners-global-ajax[data-pb-cat*=pb_ente]', 'click', function(event) {
event.preventDefault();
var pb_cat = "pb_ente";
var data = {
    'action': 'GetPostEnte',
    catURL : "loop_"+ pb_cat,
};
$.post(ajaxURL, data, function(response) {
    $( 'ul.homus-partners-section-slide' ).html(response);
});

});

$(document).delegate('h4.homus-partners-global-ajax[data-pb-cat*=pb_coll]', 'click', function(event) {
event.preventDefault();
var pb_cat = "pb_coll";
var data = {
    'action': 'GetPostColl',
    catURL : "loop_"+ pb_cat,
};

$.post(ajaxURL, data, function(response) {
    $( 'ul.homus-partners-section-slide' ).html(response);
});

});

$(document).delegate('h4.homus-partners-global-ajax[data-pb-cat*=pb_media]', 'click', function(event) {
event.preventDefault();
var pb_cat = "pb_media";
var data = {
    'action': 'GetPostMedia',
    catURL : "loop_"+ pb_cat,
};
$.post(ajaxURL, data, function(response) {
    $( 'ul.homus-partners-section-slide' ).html(response);
});

});

$(document).delegate('li.homus-partners-section-single', 'click',                         function(event) {
  event.preventDefault();
  var pb_post_id = $(this).data('post-id');
  var data = {
    'action': 'GetPostDetails',
    postURL : "single_pb_post_details",
    post_id: pb_post_id
  };
  $.post(ajaxURL, data, function(response) {
      $( '.homus-partners-detalis' ).html(response);
      console.log(pb_post_id);
      console.log(data.postURL);
      console.log(response);
  });

});

the response that I have is always 0 even if the console of the last ajax call here above return the right postid. You can find the whole project in this repo https://github.com/wanbinkimoon/homus-web.git

  • 写回答

1条回答 默认 最新

  • dqwh1218 2016-03-02 12:14
    关注

    in the code

    function GetPostPartner(){
    $catPartner = "loop_pb_partner";
    get_template_part($catPartner);
    wp_die();
    }
    add_action('wp_ajax_nopriv_GetPostPartner', 'GetPostPartner');
    

    instead of including the file by get_template_part paste the code here and then try

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 无源定位系统的时差估计误差标准差
  • ¥15 请问这个代码哪里有问题啊
  • ¥20 python--version在命令端输入结果Python is not defined怎么办?还有pip不是exe格式是不是没安装成功?
  • ¥15 通过GaussianView进行结构微调消除虚频
  • ¥15 调用transformers库
  • ¥15 由于导出的数据名字中带有/,导致Matlab打不开,怎么办?
  • ¥15 新硬盘安装的程序总是崩溃,提示遇到错误
  • ¥15 openpcdet自制数据集评估bev精度和3d精度相同
  • ¥15 excel 上下按钮 显示行
  • ¥20 云卓h12pro 数传问题