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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:15:59+00:00 2026-06-08T12:15:59+00:00

I am getting data dynamically using jQuery AJAX requests. The Ajax calls are nested,

  • 0

I am getting data dynamically using jQuery AJAX requests. The Ajax calls are nested, they are called in the success function of each previous request. I am doing this to not put too much load on the server. The next request should only be sent if the previous one is completed or successful.

Here is the ajax code

function showforLanguagetra(option, catid, meta)
{
    $.ajax({       ///execute only if catid = 1,3,6,8
        type:"GET",
        url: "/Ajax1111",
        data: {
            opt: option,
            cid: catid,
            mta: meta
        },
        success: function(data){
            $("#1111").html(data);

            $.ajax({           ///execute only if catid = 5,7,9
                type:"GET",
                url: "/Ajax2222",
                data: {
                    opt: option,
                    cid: catid,
                    mta: meta
                },
                success: function(data){
                    $("#2222").html(data);


                    $.ajax({            ///execute only if catid = 2,5,4,8
                        type:"GET",
                        url: "/Ajax3333",
                        data: {
                            opt: option,
                            cid: catid,
                            mta: meta
                        },
                        success: function(data){
                            $("#3333").html(data);


                            $.ajax({               ///execute only if catid = 6,4,8,9,0
                                type:"GET",
                                url: "/Ajax4444",
                                data: {
                                    opt: option,
                                    cid: catid,
                                    mta: meta
                                },
                                success: function(data){
                                    $("#4444").html(data);


                                    $.ajax({              ///execute only if catid = 2,3,5,7,4
                                        type:"GET",
                                        url: "/Ajax5555",
                                        data: {
                                            opt: option,
                                            cid: catid,
                                            mta: meta
                                        },
                                        success: function(data){
                                            $("#5555").html(data);
                                        }
                                    });        
                                }
                            });      
                        }
                    });        
                }
            });     
        }
    }); 
}    ​

This code is Working Fine !

But what here required is , I want to execute ajax request based on value in catid as shown in comments in ajax code.
I know it lags in if condition but am new to jQuery AJAX so don’t know where and how to use it

  • 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-08T12:16:00+00:00Added an answer on June 8, 2026 at 12:16 pm

    I think perhaps what you really want is simply the async: false part – this makes the ajax call complete before proceeding throught the code.

    I have updated this answer as I don’t believe you want all following calls to not fire, rather they should all fire in order and dependent on catid


    To do this you will need to put if or switch blocks round your ajax calls. This will lead to even deeper nesting than you already have.

    I would strongly recommened breaking this logic out into separate routines. Have one function which calls the ajax routine rather than this deep nesting.

    Set async to false to make the ajax routine wait for success before continuing.

    function callAjax( service , option catid , meta ) {
       var ret = {data:false};
    
        $.ajax({       
            type:"GET",
            url: service,
            async: false,
            data: {
                opt: option,
                cid: catid,
                mta: meta
            },
            success: function(data){
                ret.data = data;
            });
    
        return ret;
    }
    
    
    function showforLanguagetra(option, catid, meta) {
        var successData;
    
        if ( catid == 1 || catid == 3 || catid == 6 || catid == 8) {
            successData = callAjax( '\Ajax1111' , option , catid, meta ).data
            if ( successData )
                $("#1111").html(successData);
        }
    
        if ( catid == 5 || catid == 7 || catid == 9) {
            successData = callAjax( '\Ajax2222' , option , catid, meta ).data
            if ( successData )
                $("#2222").html(successData);
        }
    
        if ( catid == 2 || catid == 5 || catid == 4 || catid == 8) {
            successData = callAjax( '\Ajax3333' , option , catid, meta ).data
            if ( successData )
                $("#3333").html(successData);
        }
    
        // etc etc
    
    }
    

    Note that your code doesn’t really make sense as if catid does not equal 1, 3, 6 or 8 then the later ajax calls will never be hit anyway…

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

Sidebar

Related Questions

I'm building some <table> data dynamically using jQuery, but I'm getting the following error:
Just started using AJAX today via JQuery and I am getting nowhere. As an
I am getting data from iphone using php but when i insert post data
I was looking at adding rows dynamically to my HTML table using jQuery with
I am getting strange behaviour when trying to upload files, using jQuery multi-file plugin,
I'm using jQuery to dynamically change the background image on a div. Here's my
We're building a web app, and it's using jquery ajax and jsp on the
Im getting data from a server by executing this code: - (void) sendGeneral:(NSString *)
how can i getting data from listbox in second form named listform while i
I am getting data nightly from a web service that stores their fields in

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.