weixin_33724059 2013-10-11 22:54 采纳率: 0%
浏览 32

新手的Wordpress Ajax

I am having issues particularly using Ajax post within an Ajax Post. Please enlighten me if this is possible.

My scenario goes like this.

I am using Wordpress and Bootstrap for my theme. I have a post type for "products" which I want to load using Ajax and have been successfully implemented them individually (for testing purposes) using Wordpress post with Ajax on click as well as using Bootstrap modal to load another Ajax post using Modal via Ajax Post.

I am not a hardcore PHP nor jQuery programmer and I want to know if this 2 can be combined in one code which would be like:

On first click will show the first Ajax post, and on the second click inside the first Ajax post will load Bootstrap modal via Ajax as well.

Here are the format of my initial codes ---

jQuery:

// AJAX POST / stackoverflow.com/questions/15402239/how-to-load-wordpress-post-with-ajax-onclick
// Calls archieve-products.php
$.ajaxSetup({cache:false});
$("a.ajax").click(function(){
    var post_url = $(this).attr("href");
    var post_id = $(this).attr("rel");
        $("#brand-default").hide();
        $("#brand-listing").show().html('<div class="loading"></div>');
        $("#brand-listing").load(post_url);
    return false;
});

// MODAL VIA AJAX POST / wpquestions.com/question/showChrono/id/7922
// Opens modal.php
$('[data-toggle="modal"]').click(function(e) {
    e.preventDefault();
    var href = $(this).attr('href');
        if (href.indexOf('#') == 0) {
            $(href).modal('open');
        } else {
            $.get(href, function(data) {
            $('<div id="brands" class="modal hide fade">' + data + '</div>').modal();
        });
    }
});

HREF from custom page template:

<a href="<?php echo $cpt_onomy->get_term_link( $term, $term->taxonomy ); ?>" rel="<?php the_ID(); ?>" class="ajax">

HREF from archive page template:

<a href="<?php bloginfo('template_url');?>/modal.php?ID=<?php the_ID(); ?>" data-toggle="modal">

I hope the codes I have provided is enough to help me. Many thanks in advance :)

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 求一段fortran代码用IVF编译运行的结果
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 lammps拉伸应力应变曲线分析
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
    • ¥30 python代码,帮调试,帮帮忙吧
    • ¥15 #MATLAB仿真#车辆换道路径规划