Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery each - loop through json?
    primarykey
    data
    text
    <p>I am passing some json to the frontend. I want to loop through it and generate some HTML. Unfortunately what I have is not looping, it is just going through the first row.</p> <pre><code>Object 1: Object date_created: "Oct. 24 2011" date_expired: "Oct. 31 2011" expire: "Oct. 31 2011" expired: 0 id: "1" name: "1" pages: 0 photos: 0 status: "Live" __proto__: Object 2: Object date_created: "Nov. 24 2011" date_expired: "Nov. 31 2011" expire: "Nov. 31 2011" expired: 0 id: "1" name: "1" pages: 0 photos: 0 status: "Live" __proto__: Object </code></pre> <p>My JavaScript</p> <pre><code>$.ajax({ type: "POST", url: "dashboard.php", data: "galleryPage="+$(this).html(), }).done(function( data ) { console.log(data); $.each(data, function(key, album) { var html = ''; $('#dashboard .row').remove(); // Make the HTML row... // Append $('#dashboard .inner').append(html); }); }); </code></pre> <p>It would appear I cannot use .each() to loop through this kind of object. Is this correct? If so what can I use to loop through this?</p> <p><strong>After an error of staring at the same code... worked it out. I'm an idiot. Was removing the row at the start of the loop instead of before it. This is why only one result ever showed up... duh</strong></p> <p>Solution</p> <pre><code>$.ajax({ type: "POST", url: "dashboard.php", data: "galleryPage="+$(this).html(), }).done(function( data ) { $('#dashboard .row').remove(); $.each(data, function(key, album) { var html = ''; // Make the HTML row... // Append $('#dashboard .inner').append(html); }); }); </code></pre>
    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