0

I'm working on a task I need to display Post Content-Img-Title on click without reload the page.

I've coded Below code:

// code for ajax portfolio
jQuery('span#ajax_post_abc a').click(function(){
    var portfolio_post_id= jQuery(this).attr('id');
    var ajaxurl = jQuery('#ajax-script-url').val();

    jQuery.ajax({
        type: 'POST',
        url: ajaxurl,        
        data: {
            "action": "load-filter2", 
            port_post_id: portfolio_post_id 
        },
        success: function(response) {
            jQuery(".aajax-post-content").html(response); }  
        });
    });

    //New Ajax portfolio div 
    jQuery('#ajax_post_abc').click(function() {
        jQuery(this).addClass('aajax-post-content');
    });  

And the resultant response in will be displayed in aajax-post-content div. But the problem is if I have n posts and I click on n+1, n+2 and so on it does not shows the output. But if I click on the very first Post n0 then it will show the output as I need.

4

6 回答 6

2
content.append('<div class="item"><span>' +data + '</span></div>');
于 2013-09-16T13:45:50.483 回答
0
Use On method instead of Click function because when multiple clicks are to be included,it never works,So Change your code as

$(document).on( 'click','#ajax_post_abc', function (e) {
    jQuery(this).addClass('aajax-post-content');
});

谢谢维兹...

于 2013-09-16T14:18:11.710 回答
0

替换#content为您想要的任何选择器。

$('<div>new content</div>').appendTo($('#content'));
于 2013-09-16T14:13:47.767 回答
0

jQuery.html() 替换项目的内部 html。jQuery.append() 将一个新元素作为子元素添加到指定容器中。

听起来你需要 append()

于 2013-09-16T13:43:37.700 回答
0

您的代码只会显示最近发生的更改。

如果您想查看每个更改,您必须附加更改并使用 .append 而不是 .html

例如:

jQuery(".aajax-post-content").append(response);
于 2013-09-16T13:43:02.643 回答
0

尝试这个

jQuery('span#ajax_post_abc a').click(function(){
    var portfolio_post_id= jQuery(this).attr('id');
    var ajaxurl = jQuery('#ajax-script-url').val();

    jQuery.ajax({
        type: 'POST',
        url: ajaxurl,        
        data: {
            "action": "load-filter2", 
            port_post_id: portfolio_post_id 
        },
        success: function(response) {
            jQuery(".aajax-post-content").html(response);
            jQuery(#ajax_post_abc).addClass('aajax-post-content');
             }  
        });
    });
于 2013-09-16T13:52:57.560 回答