A piece of code processes the input line taken from the base, if the line length is more than 1000 characters, it is paginated and poured into the block with the addition of page switches On the first pass, that is, immediately after the page loads (and the first access to the database) everything goes as need to. But if the user initiates an AJAX call to replace the text (not the page, but the entire text for the block), the browser loops on the third to sixth line
if(ii>item.page_text.length){ ii=item.page_text.length; ii--; } Question: why?
Important clarification The code does not just divide the line into fragments of 1000 characters. He is looking for the nearest end of the sentence indicated by a dot in the direction of decreasing the number of characters.
Here is the responsible piece of code
var i=0; var ii=0; pageText=new Array(); for( ii=1000;i<item.page_text.length-1;ii=i+1000) { if(ii<item.page_text.length){ while(ii>i){ if (item.page_text[ii]!="."){ ii--; } else { ii++; pageText.push("<p>"+item.page_text.slice(i,ii)+"</p>"); i=ii; $(".book-text-choose-first").before("<span class=\"book-text-page-num\" id=\"page#"+pageText.length+"\">"+pageText.length+"</span>"); break; } } } else{ ii=item.page_text.length-1; } }
iat the very beginning of the given fragment? - Sergiksvar i=0- Konorlevich