Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7894279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:21:18+00:00 2026-06-03T07:21:18+00:00

Javascript/JQuery noob here, so apologies. I’m using .ajax to get a JSON object then

  • 0

Javascript/JQuery noob here, so apologies.

I’m using .ajax to get a JSON object then the code below to loop through and append the fields to the page. Easy.

$.each(data, function(i, item) {
    $("#div-ipos").append(
        "<img src=" + item.user.avatar_small_url + ">&nbsp;"
        + item.user.first_name 
        + "<hr /><br />"
    );
});

It works and the output is as expected, complete with the avatar path passed into an <img> tag.

However I get the following error:

TypeError: ‘undefined’ is not an object (evaluating ‘item.user.avatar_small_url’)

What do I need to do to that variable to make it behave properly in this context?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:21:20+00:00Added an answer on June 3, 2026 at 7:21 am

    Use console.log(data); before your $.each to check what’s in it. Most likely the server response contains an extra array element with no user. So the JSON could look like:

    [{"user":{"avatar_small_url":"foo","first_name":"bar"}},
     {"user":{"avatar_small_url":"bar","first_name":"foo"}},
     {"something_other_than_user":9000}]
    

    See how the last array element doesn’t have a “user”. If you have access to the server code, you may want to modify it so there is always a user, or you may modify your Javascript so that it exits early if the user field doesn’t exist with something like: if(typeof item.user == 'undefined') return;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the script shown below. <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js' type='text/javascript'> <script type='text/javascript'> var sidebarnameacc1=&quot;sidebar&quot;;
javascript noob trying to figure something out. I saw a script located here: Using
javascript noob here. So I'm trying to use this s3 uploader jQuery example here
I am a complete jQuery and Javascript noob trying to get a very simple
I have a javascript/jQuery block as a callback after $.get function: function myCallBack(data, textStatus)
I am using Javascript-JQuery to submit 2 aspx pages, $('#MyForm1').submit(); $('#MyForm2').submit(); for some reason
jQuery noob here (don't most posts start like that?) I know I could do
Here's my problem : i'm lvl 0 in javascript and jquery. (i developp webapps
i'm new here & i'm a noob with javascript, so please, be gentle &
JavaScript (JQuery) $('input').keyup(function(e) { var code = e.keyCode ? e.keyCode : e.which; switch(code) {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.