【问题标题】:Jquery Accordion not firing on ajax callJquery Accordion 没有在 ajax 调用上触发
【发布时间】:2013-01-15 10:57:25
【问题描述】:

我将输出页面中的源代码复制到下面的文件中,这样您就可以看到我在说什么:

http://playerspace.com/mysource.html

我们正在查看的是最近的活动 ajax(由于某种原因,它不适用于此输出版本)。我希望只看代码就足以诊断它。

无论如何,问题在于“cmets”链接,它是一个手风琴,显示了一个扩展的文本区域。在时间轴中接下来的 5 个项目的 ajax 加载后,cmets 链接(部分或全部)完全停止响应。

我尝试将手风琴代码直接添加到 ajax 调用中,但仍然无法始终如一地执行。

    $(document).on("click",'.siteusemore',function()
    {
    var ID = $(this).attr("id");
    var myscript = window.siteusemore_script || null;       
    if(ID)
    {
    $("#siteusemore"+ID).html('<img src="/images/processing.gif" />');                  
    $.ajax({
    type: "POST",
    url: myscript,
    data: "lastmsg="+ ID, 
    cache: false,
    success: function(html){                                    
        $("ol#siteuseupdates").append(html);                                            
        $("#siteusemore"+ID).remove();
        $('.accordionContent,.accordionContent-settings').hide();   
        $('.accordionContent,.accordionContent-manuallyadd').hide();                                
        $('.accordion-comments').live("click",function(event){
        var target=$(this).attr('href');
        if($(target).css('display')=='none')
        {
            $(target).show();
            $(this).text('Hide Comments');
        }
        else
        {
            $(target).hide();
            $(this).text('Comments');
        }
        return false;
        });                         
    }
    });
    }
    else
    {
        $(".siteusemorebox").html('The End');
        $('.accordionContent,.accordionContent-settings').hide();   
        $('.accordionContent,.accordionContent-manuallyadd').hide();                                
        $('.accordion-comments').live("click",function(event){
        var target=$(this).attr('href');
        if($(target).css('display')=='none')
        {
            $(target).show();
            $(this).text('Hide Comments');
        }
        else
        {
            $(target).hide();
            $(this).text('Comments');
        }
        return false;
        });                         
    }               
    return false;
});

我刚开始使用 ajax,我可以在这里使用帮助。我想我的问题是让在我的 site.js 文件(位于页面底部)中执行的代码与每个 ajax 加载一致地触发?

我也不知道这是否有帮助,但问题似乎出现在所有其他 ajax 调用上,这很奇怪。

【问题讨论】:

  • 你能提供你用过的jquery版本吗?

标签: jquery ajax accordion


【解决方案1】:

我认为您需要重新启动手风琴。将此代码添加到您的成功 ajax 调用回调中:

$("#accordion").accordion("destroy");
$("#accordion").accordion({collapsible: true,header: "h3",active: false});

这应该在正确的 div 上应用手风琴,请用“h3”替换您的标题 div。

【讨论】:

  • 那个好像没什么效果。
  • 另外澄清一下,它不是真正的手风琴,只是一个显示隐藏类型的交易。
  • 对不起,我没有看到你们。你解决问题了吗?您可以随时尝试 jequery $.post [api.jquery.com/jQuery.post/],它具有更简单的 sintax,对于初学者来说可能是更好的解决方案。
  • 另外,从我能够使用 firebug 验证的内容来看,您正在将 HTTP POST 中的参数作为 URL 查询字符串而不是 HTTP POST 正文传递给服务器。
猜你喜欢
  • 2020-05-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-17
  • 1970-01-01
相关资源
最近更新 更多