Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery use .slice().each to start the loop on a different index
    text
    copied!<p>I am in need of reading an incremented XML file. So using a recursive function I pass the value of the latest <code>index</code> to <code>.slice().each</code> but for some reasons when the function is called again it stops completely. What's wrong? Why it does not slice to the next specified index? What's wrong in my code?</p> <pre><code>function processXML(indexValue) { var tocURL = "../broadcasted.xml"; $.get(tocURL, function(d) { var length = $(d).find('tweet').length; var count = indexValue; $(d).find('tweet').slice(count).each(function(index) { var cvdIndexId = $(this).find("index"); var cvdTweetAuthor = $(this).find("author").text(); var cvdTweetDescription = $(this).find("description").text(); setTimeout(function() { if (index == (length - 1)) { processXML(index + 1); //alert(index+1); } else if (cvdTweetAuthor === "Animator") { $('#cvd_bubble_left').html(''); obj = $('#cvd_bubble_left').append(makeCvdBubbleAnimator(cvdIndexId, cvdTweetAuthor, cvdTweetDescription)); obj.fitText(7.4); $('#cvd_bubble_right').html(''); } else { $('#cvd_bubble_right').html(''); obj = $('#cvd_bubble_right').append(makeCvdBubble(cvdIndexId, cvdTweetAuthor, cvdTweetDescription)); obj.fitText(7.4); $('#cvd_bubble_left').html(''); } }, index * 1000); }); }); } &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;root bubbles="7"&gt; &lt;tweet broadcasted="bubble"&gt; &lt;author&gt;&lt;![CDATA[@Liciiious]]&gt;&lt;/author&gt; &lt;description&gt;&lt;![CDATA[#EveryoneLovesBeinsport (cc @beinsport @charlesbietry). #pureLIVE]]&gt;&lt;/description&gt; &lt;index&gt;1&lt;/index&gt; &lt;/tweet&gt; &lt;tweet broadcasted="bubble"&gt; &lt;description&gt;&lt;![CDATA[Message]]&gt;&lt;/description&gt; &lt;author&gt;&lt;![CDATA[beIN Sport]]&gt;&lt;/author&gt; &lt;index&gt;2&lt;/index&gt; &lt;/tweet&gt; &lt;tweet broadcasted="bubble"&gt; &lt;author&gt;&lt;![CDATA[@Liciiious2]]&gt;&lt;/author&gt; &lt;description&gt;&lt;![CDATA[#EveryoneLovesBeinsport (cc @beinsport @charlesbietry). #pureLIVE]]&gt;&lt;/description&gt; &lt;index&gt;3&lt;/index&gt; &lt;/tweet&gt; &lt;tweet broadcasted="bubble"&gt; &lt;description&gt;&lt;![CDATA[Message]]&gt;&lt;/description&gt; &lt;author&gt;&lt;![CDATA[Animator]]&gt;&lt;/author&gt; &lt;index&gt;4&lt;/index&gt; &lt;/tweet&gt; &lt;tweet broadcasted="bubble"&gt; &lt;author&gt;&lt;![CDATA[@MAuricious]]&gt;&lt;/author&gt; &lt;description&gt;&lt;![CDATA[#EveryoneLovesBeinsport (cc @beinsport @charlesbietry). #pureLIVE]]&gt;&lt;/description&gt; &lt;index&gt;5&lt;/index&gt; &lt;/tweet&gt; &lt;tweet broadcasted="bubble"&gt; &lt;description&gt;&lt;![CDATA[Message]]&gt;&lt;/description&gt; &lt;author&gt;&lt;![CDATA[beIN Sport]]&gt;&lt;/author&gt; &lt;index&gt;6&lt;/index&gt; &lt;/tweet&gt; &lt;tweet broadcasted="bubble"&gt; &lt;description&gt;&lt;![CDATA[Messagexxx]]&gt;&lt;/description&gt; &lt;author&gt;&lt;![CDATA[beIN Sportxxx]]&gt;&lt;/author&gt; &lt;index&gt;7&lt;/index&gt; &lt;/tweet&gt; &lt;tweet broadcasted="bubble"&gt; &lt;description&gt;&lt;![CDATA[Messagexxxzzzz]]&gt;&lt;/description&gt; &lt;author&gt;&lt;![CDATA[beIN Sportxxxzzzz]]&gt;&lt;/author&gt; &lt;index&gt;8&lt;/index&gt; &lt;/tweet&gt; &lt;/root&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload