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 8232253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:46:16+00:00 2026-06-07T17:46:16+00:00

I’m writing a small Flickr image grabber app, and we have a JSON proxy

  • 0

I’m writing a small Flickr image grabber app, and we have a JSON proxy on our own servers. The function below grabs the images from a photoset given the id.

function getPhotosFromPhotoset(p_id) {
    var data;
    $.getJSON('/flickr_get_photos', {
        photoset_id: p_id
    }, function(res) {
        data = res;
        console.log("res: " + JSON.stringify(data));
        if (res.status == 'ok') {
            if (res.data.length > 0) {
                //nada                                                                                                                            
            } else {
                data.status = "error: Photoset has no photos.";
            }
        } else {
            data.status = "An unknown error occurred; please try again.";
        }
    });
    return data; //undefined?!
}

Why is does data suddenly become undefined? When I console.log it inside of the getJSON, it’s perfectly valid.

  • 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-07T17:46:19+00:00Added an answer on June 7, 2026 at 5:46 pm

    The function returns long before the ajax request is even made. Use data in the callback function (You are actually logging it in the callback function, where it’s guaranteed to be available ). The $.getJSON doesn’t take callback function just for fun, but exactly for this reason.

    You can do this though:

    function getPhotosFromPhotoset(p_id) {
        return $.getJSON('/flickr_get_photos', {
            photoset_id: p_id
        });
    }
    
    getPhotosFromPhotoset(1).then(function(data) {
        //Use data here
    });
    

    Instead of trying to do:

    var data = getPhotosFromPhotoset(1); //will not work
    

    Which will not work unless you set the request to synchronous, which has worse problems.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
I am writing an app with both english and french support. The app requests
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.