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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:13:17+00:00 2026-05-27T09:13:17+00:00

I’ve got a successful call going out to a coldfusion database controller using jQuery’s

  • 0

I’ve got a successful call going out to a coldfusion database controller using jQuery’s getJSON method. The returned information comes back in the format:

{
    "COLUMNS": ["PRODUCT_HIERARCHY", "WEBPRODLINE", "POSITION", "FEATURES", "BENEFITS", "LINKS", "VIDEOS", "IMAGE_CUTAWAY", "MARKEDASNEW"],
    "DATA": [
        ["23456689", "ProdName1", "A Feature 1", "A Benefit 1", "url", "vid_url", "img_name", "N"],
        ["234566891", "ProdName2", "A Feature 2", "A Benefit 2", "url", "vid_url", "img_name", "N"]
    ]
}

I now want to store the returned information as an object that I can then filter locally instead of making another call to the db. The problem is in the initializeView function. Here’s the relevant script:

$(document).ready(function() {

    var productsFlag = false;
    var enableLog = true;

    var allProducts = $.getJSON(jsonURL, { method: "getAllProducts", returnformat: "json" }, function(data) {
        productsFlag = true;
    });

    waitOnJson();

    function waitOnJson() {
        //this shows up in the log
        logThis('areProductsReady?');
        if (productsFlag) {
            //this shows up in the log
            logThis('productsFlags ready');
            initializeProductView();
        } else {
            //this shows up in the log
            logThis('productsFlags not ready');
            t = setTimeout(waitOnJson, 100);
        }
    }

    function initializeProductView() {
        //this shows up in the log
        logThis('initializeProductView');
        //this displays [object Object]
        alert(allProducts);
        //this displays undefined
        alert(allProducts.DATA);
        $.each(allProducts.DATA, function(i, item) {
            //this doesn't show up in the log
            logThis(item[1]);
        });
    }

    //as you can tell, this writes out to a debug console on the page
    function logThis(eventString) {
        if (enableLog === true) {
            $('<p/>').append(eventString).appendTo("#log");
        }
    }

});

I’m sure that the problem is in my lack of understanding about what getJSON is returning but I’ve either had too much caffeine or not enough and I’m not seeing it. HELP!

Also, any thoughts on my blocking wait step? I want to be able to use the data in several different functions but I also need to wait for it to load before initializing the view.

  • 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-27T09:13:17+00:00Added an answer on May 27, 2026 at 9:13 am

    First things first, you shouldn’t have to wait on the json response like you are. The function in your getJSON method call only returns when a response is received. When it does, it returns the results of your JSON call as the first argument of the method call. So you can just do something like this (I stripped a lot of your stuff out for simplicity sake):

    $(document).ready(function() {
    
        $.getJSON(jsonURL,
        {
            method: "getAllProducts",
            returnformat: "json"
        }, function(allProducts) {  //This function only executes when the response is received.
    
            //You access your products array here and do whatever you need with them
            alert(allProducts != null);
    
        });
    
    
    });
    

    Hopefully that clears things up somewhat.

    EDIT: After reading your comment, if the alerts in your initializeProductView method are what you’re confused about, it’s probably because the getJSON method doesn’t return the result of the JSON AJAX request, it returns an jqXHR object. That’s why the .DATA attribute is undefined. If you did something to the effect of this, it would potentially work (assuming your returned JSON has a .DATA member):

    var allProducts = null;
    
    $.getJSON(jsonURL,
        {
            method: "getAllProducts",
            returnformat: "json"
        },
        function(data) {
            productsFlag = true;
            allProducts = data;
        }
    );
    

    Sorry about my misunderstanding earlier.

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

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am reading a book about Javascript and jQuery and using one of the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
i got an object with contents of html markup in it, for example: string

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.