Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Jhonnatan, I'm glad you got your code working. So this isn't really an "answer" to your original question. But you also asked for tips on the coding and how to improve it. That's great that you're looking for ways to improve your code!</p> <p>Here's one suggestion for you, a simpler way to write the <code>checkUser()</code> function. This is just a direct conversion of your function that should work with the same data format.</p> <pre><code>function checkUser() { console.log( "clicked" ); var user = $(this).html(); $.getJSON( "js/options.json", function( json ) { $.each( json.chat.OnlineContacts, function( i, contact ) { if( user == contact.name ) { displayChatWindow( contact.name, contact.status, contact.avatar ); console.log( contact.avatar ); } }); }); } </code></pre> <p>Note how the use of the <code>contact</code> object makes it unnecessary to create all those <code>jsonUserXxxx</code> variables, because code like <code>contact.avatar</code> is just as simple and clear as <code>jsonUserAvatar</code>.</p> <p>I also highly recommend <a href="https://stackoverflow.com/a/16972266/1202830">@DaveRomero's excellent answer</a> for a more strategic look at the question of how best to structure your JSON data.</p> <p>More related reading: <a href="https://stackoverflow.com/a/16971541/1202830">this discussion of JSON restructuring</a> that I posted in response to <a href="https://stackoverflow.com/questions/16970265/find-json-nested-nodes-using-multiple-string-values">this question</a> earlier today.</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. VO
      singulars
      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