rviscomi / trunk8

jQuery Truncation Plugin -- THIS PROJECT IS NO LONGER MAINTAINED
MIT License
703 stars 95 forks source link

trunk8 doesn't work with $.ajax #36

Open ds-1010 opened 11 years ago

ds-1010 commented 11 years ago

Hi! I have faced with strange problem. If i use trunk8 in $.ajax call, for example

$.ajax({
      url: parameters.source,
      type: "POST",
      dataType: "json",
      async: false,
      data: ajaxData,
      success: function (data) {                    
          item = createItem(data);
          $('#some_id').append(item);
          item.find('.too-long').trunk8();
      }
});

nothing happens. Text not truncated.

But if i call for example

$(document).ready(function() {
    item = createItem( {Id :1, Name : "Test name"} );
    $('#some_id').append(item);
    item.find('.too-long').trunk8();
});

all works fine. Could you explain me such behavior.

Thank you in advance.

ibigpapa commented 10 years ago

var resultsPage = "http://10.14.191.153/snmp/bkgsearch2.php?query="; var terms = ''; $(document).ready(function(){ $("#srcc").keyup(function(event){ if(event.keyCode == 13){ $("#srcbtn").click(); } }); $('#menu').load('menu.html'); $('#srcbtn').click(function(){ terms = $('#srcc').val(); if(terms !== ''){ var loadPage = resultsPage.concat(terms); $('#resultwrapper').load(loadPage,function(){ //$('#resultwrapper').removeHighlight(); //$('#resultwrapper').highlight(terms); $('#trunk').trunk8({lines:2, fill: '… read more '}); $('#read-more').live('click',function (event){ $(this).parent().trunk8('revert').append(' read less'); return false; }); $('#read-less').live('click',function (event){ $(this).parent().trunk8(); return false; }); }); } }); });

It appears i'm having the same issue as you. Execept it'll truncate the first elelment on my page.

s1h4d0w commented 9 years ago

Hi dsys,

Are you sure there are no errors? It works for me if I call the Trunk8 function after the content is succesfully appended. This code works flawlessly for me:

function loadMore() {
    $.ajax({
        url: "loadmore.php",
        success: function(html){
            $(".content").append(html);
            $(".trunk8").trunk8();
        }
    });
    return false;
}

My content is in a span which sits in a table cell. The span has the trunk8 class.