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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:14:21+00:00 2026-06-04T07:14:21+00:00

Inside a $.getJSON success function, I first trigger another element’s click event: $(‘#’ +

  • 0

Inside a $.getJSON success function, I first trigger another element’s click event:

$('#' + data[0].ID).trigger('click');

The triggered click event has its own $.getJSON method to load a bunch of data into divs.
The next line after the triggered event:

$.each(data[0].ListEntries, function (key, val) {
        //this relies on the triggered click event 
        //having completely loaded all data!
}

At first the $.each didn’t appear to be doing anything, but I added an alert right after the triggered event.
After responding to the alert, the code in $.each shows what it’s supposed to.

I’m guessing $.each is running before the click event finishes loading the data.

setTimeout pauses long enough for the click event to load data, but I’d rather not set an arbitrary time:

setTimeout(function() { 
    $.each(data[0].ListEntries, function (key, val) {
        //this relies on the triggered click event 
        //having completely loaded all data!
    }
}, 1000);

I also tried $.when and $.then to no avail (although adding alert before $.each inside $.then creates delay for $.each to work):

$.when($('#' + data[0].ID).trigger('click')).then(function () {
    $.each(data[0].ListEntries, function (key, val) {
        //this relies on the triggered click event 
        //having completely loaded all data!
    })
  • 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-04T07:14:22+00:00Added an answer on June 4, 2026 at 7:14 am

    Tidied up for greater clarity

    .trigger() returns a jQuery object so you are denied the option of doing $.when() ... $.then().

    On the other hand, .triggerHandler(), will return an object of your choice, thus making it possible to do the deferred trick.

    Your code is organised in three functions, simplified below. The call path is 1,2,3 and the all-important return path is 3,2,1.

    (1) The highest level (JSON success) function will include the following lines :

    function() {
        ...
        $.when($('#' + data[0].ID).triggerHandler('click')).done(function() {
            $.each(data[0].ListEntries, function (key, val) {
                ...
            });
        });
        ...
    };
    

    (2) The click handler triggered by (1), will be as follows :

    $("img.Button").on("click", function () {
        return GetModels(this.id);//here `return` passes on the jqXHR object, up the return path.
    });
    

    (3) And the lowest level function containing the JSON, on which (1) depends, will be of this general form :

    function GetModels(id) {
        ...
        var jqXHR = getJSON(function(){...});
        ...
        return jqXHR;//it is vital to retutn the jqXHR object arising from the json call.
    }
    

    Notes :

    • The return path delivers, as the “promise” argument to the .when() method in (1), the jqXHR object arising from the .getJSON() call in (3). The chained .done() in (1) is thus forced to wait for the jqXHR to be resolved (ie. complete) before firing the function that is provided as its argument.
    • The click handler makes no assumptions about how it is invoked. It simply returns the jqXHR object. Thus when invoked with .triggerHandler(), the click handler can have additional behaviour appended to it without affecting the normal click action.
    • It would be simpler to call GetModels() directly from (1), cutting out the middle-man (2), which is fine if GetModels() behaviour is uniquely wanted. If, however, (1) needs to be responsive to any future changes to the triggered click handler (2), then the above approach needs to be adopted.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using getJSON to populate form elements inside function(data) {...} by concatenating html.
I'm trying to use $.getJSON inside $.post function and display returned value in textbox
Inside of a jQuery plugin I made I have: $.getJSON(base_url,{ agenda_id:defaults.id, action:defaults.action+defaults.type, output:defaults.output },function(json){
I am trying to access some data from my server inside another domain. So
Here is my code. My question has to do with the append function inside
// inside $(document).ready function... var name = ''; function test() { $.post('/student/get-info', function(data) {
So far, I have got the following: $.getJSON('getinfo.php', { id:id }, parseInfo); function parseInfo(data)
I'm using a jQuery JSON function inside another function, how can I return an
Consider the following example: var features = []; $.getJSON(annotations_url, function(data) { $.each(data, function(key, val)
Inside my template function I have the following code: TypeName myFunction() { TypeName result;

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.