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

  • SEARCH
  • Home
  • 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 6624267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:37:54+00:00 2026-05-25T21:37:54+00:00

getGood = function(v,x) { $.getJSON(‘json/products.json’, function(data) { $.each(data, function(key, val) { if (v.toLowerCase() ==

  • 0
getGood = function(v,x) {
    $.getJSON('json/products.json', function(data) {
        $.each(data, function(key, val) {
            if (v.toLowerCase() == key.toLowerCase()) {
                $.each(val.products, function(ckey, cval) {
                    if (x.toLowerCase() == ckey.toLowerCase()) {
                        var dval=new Date().getDay();
                        var qHash=hex_md5(v+x+qs('cst')+dval).toLowerCase();    
                        if (qHash == qs('hash')) {
                            return dval;
                        } else {
                            window.location.replace('/errors/418.html');
                        }
                    }                
                });
            }
        });
    });
}

$(document).ready(function() {
    var owner=getGood(qs('cat'),qs('subp'));
    alert(owner==null);
    $('.content_title').html(qs('subp'));
    $('.description').html(owner.descripion);
})

The above code is supposed to read a JSON file, compare some query strings to test for validity and then return the object if the request is valid. Problem is, no matter what I do, getGood refuses to return any value to my owner variable. I’ve tried having it return the different values around it. I was just trying to get it to return anything I could. It needs to return cval. The alert at the bottom, however, always says “undefined/null”.

EDIT

Because apparently people think I am just that retarded:

YES, it gets to the return statement. Yes, qHash == qs(‘hash’), I’m not asking you to check every if/loop/etc. I already know all of that works. I’m asking, why does my return statement not end up setting owner to what it is supposed to.

  • 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-05-25T21:37:54+00:00Added an answer on May 25, 2026 at 9:37 pm

    The callback passed to “$.getJSON()” is executed asynchronously. It is therefore just not possible to return a value from it.

    Instead, pass in the code that needs to act on the value as a function parameter. The callback function can then pass the value into that function as a parameter.

    function getGood(v, x, handleOwner) {
      $.getJSON('json/products.json', function(data) {
          $.each(data, function(key, val) {
              if (v.toLowerCase() == key.toLowerCase()) {
                 $.each(val.products, function(ckey, cval) {
                    if (x.toLowerCase() == ckey.toLowerCase()) {
                        var dval=new Date().getDay();
                        var qHash=hex_md5(v+x+qs('cst')+dval).toLowerCase();    
                        if (qHash == qs('hash')) {
                            handleOwner(dval); // calling the handler function here
                        } else {
                            window.location.replace('/errors/418.html');
                        }
                    }                
                });
            }
         });
      });
    }
    
    //
    getGood(qs('cat'),qs('subp'), function(owner) {
      alert(owner);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How come the dir() function in Python doesn't show all of the callable attributes?
I have been reading templates,functors,callback function for the past week and have referred some
this is from the source code of csv2rec in matplotlib how can this function
how to get the JSON object through URL in my ruby on rails code:
Surprisingly as you get good at vim, you can code even faster than standard
I am a beginner with C++. I have a new project at work where
I'm running an ldap_list with this filter: (&(givenname=*)(objectClass=User)(!department=Executive)) and I get zero results and
I am banging my head against a mess of JNI code and DLLs that
I write a little ruby script, which sends me an email when a new
I have to write an application that is essentially a proxy server to handle

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.