Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A simple solution is to keep a variable outside the function containing the current text, and then write to that each time your <code>getRealData()</code> function is called. For example:</p> <pre><code>var currentText; function getRealData() { $.ajax({ url: "...", data: "...", dataType: "...", success: function(rows){ var text = '' // Process text variable accordingly, as you have if (text != currentText){ $("#journey").html(text).performBlinkEvent(); currentText = text; } } }); } </code></pre> <p>The performBlinkEvent function can be readily found with a search, for example <a href="https://stackoverflow.com/questions/275931/how-do-you-make-an-element-flash-in-jquery">this</a> is one post that turned up.</p> <p>Edit: Another option is to iterate through all the <code>&lt;section class="square"&gt;</code> elements on success, writing each element on success rather than the entire containing <code>#journey</code> class:</p> <pre><code>function (rows) { // Get all squares and iterate over each var squares = $("#journey &gt; .square").each( function(i) { var row = rows[i]; var availability = row[3]; var hostName = row[2]; var intranet = row[6]; var timeRespons = row[4]; // construct img var based on availabiliy var text = ... // Construct content of &lt;section class="square"&gt; if ( $(this).text() != text ){ $(this).html(text).performBlink(); } }); } </code></pre> <p>This assumes that the sections are already on the page, which I think is a fair assumption to make. It also assumes a 1 to 1 correspondence between the rows you receive and the number of sections in the page. If this is not true (i.e., the number of squares change with each response) then further logic is required.</p> <p>Here is the <a href="http://jsfiddle.net/NEckk/2/" rel="nofollow noreferrer">JSFiddle</a> for the second code snippet. I've populated a few elements with data, and then create a sample response containing the old data and some new data. The function will successfully determine which data needs to be inserted and will highlight the element that is updated.</p> <p>It will need to be adapted to the specific data the callback is receiving (as I noted in a comment to the question, it seems unlikely you are actually receiving an array of arrays from a JSON response), but I hope this demonstrates how to accomplish your goal. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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