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 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题