Note that there are some explanatory texts on larger screens.

plurals
  1. POAccess multiple objects/arrays in JSON in jQuery $.each
    primarykey
    data
    text
    <p>I am trying to build a simple page to view messages saved in a mysql db via JSON and jQuery. </p> <p><strong>My JSON IS</strong></p> <pre><code>{"unread_msgs":[{"id":"6","title":"33333","user1":"19","timestamp":"1383747146","client_id":"Generic"},{"id":"5","title":"42142","user1":"19","timestamp":"1383740864","client_id":"Generic"}],"read_msgs":[{"id":"4","title":"test to addnrow","user1":"19","timestamp":"1383676647","client_id":"Generic"},{"id":"2","title":"kll","user1":"19","timestamp":"1383675548","client_id":"Generic"},{"id":"1","title":"jkjljklj","user1":"19","timestamp":"1382539982","client_id":"Generic"}],"urm_t":2,"rm_t":3} </code></pre> <p><strong>My JS</strong></p> <pre><code>&lt;script type="text/javascript"&gt; function GetClientMsgs () { $.post("assets/server/client_msgs.php",{ client_id:local_client_id } ,function(data) { var MsgData = $.parseJSON(data); console.log("Msg json data parsed"); $.each(MsgData, function(key, value) { console.log(value); $('#unread_row').append('&lt;td&gt;&lt;a href="#read_pm" onClick="ReadMsg('+value.unread_msgs.id+'); return false;"&gt;'+value.unread_msgs.title+'&lt;/a&gt;&lt;/td&gt;&lt;td&gt;&lt;a href="#profile"&gt;'+value.unread_msgs.studioname+'&lt;/a&gt;&lt;/td&gt;&lt;td&gt;'+value.unread_msgs.timestamp+'&lt;/td&gt;&lt;td&gt;&lt;a href="#delete_msg" onClick="DeleteMsg('value.unread_msgs.id+'); return false;"&gt;X&lt;/a&gt;&lt;/td&gt;'); $('#read_row').append('&lt;td&gt;&lt;a href="#read_pm" onClick="ReadMsg('+value.read_msgs.id+'); return false;"&gt;'+value.read_msgs.title+'&lt;/a&gt;&lt;/td&gt;&lt;td&gt;&lt;a href="#profile"&gt;'+value.read_msgs.studioname+'&lt;/a&gt;&lt;/td&gt;&lt;td&gt;'+value.read_msgs.timestamp+'&lt;/td&gt;&lt;td&gt;&lt;a href="#delete_msg" onClick="DeleteMsg('+value.read_msgs.id+'); return false;"&gt;X&lt;/a&gt;&lt;/td&gt;'); }); }); } &lt;/script&gt; </code></pre> <p><strong>PHP</strong></p> <pre><code>$msgs = array('unread_msgs' =&gt; $dn1s, 'read_msgs' =&gt; $dn2s, 'urm_t' =&gt; $unread_msgs, 'rm_t' =&gt; $read_msgs); $json = json_encode($msgs); </code></pre> <p>I am trying to post values returned such as unread_msgs.title or .id and am not able to access any of the objects. I have searched on here and could not find something specific to my structure. Thanks alot.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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