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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:28:37+00:00 2026-05-31T00:28:37+00:00

I am working on an PHP application that uses ajax to load components within

  • 0

I am working on an PHP application that uses ajax to load components within a page. More importantly, these modules/components are suppose to load in a sequence such that if a previous load fails, the ones that follow will also fail.

In other words, the Page loads, makes an ajax call and receives a json encoded response. If the response was “SUCCESS”, it makes the second call and receives another json response. Again, if the second response was “SUCCESS”, it makes the 3rd call and so on. This is suppose to happen about 8 times at which point the page is considered completely loaded.

If during this load, say the 3rd request receives a response “FAIL”, the requests from 4-8 are abandoned and an error message is thrown.

The way I am achieving this right now is by making the first call, wait for response and make the second call from within the first call.

To put this in reference, here is part of the code:

$.get(WEB_ROOT+'/process/createKeywords', {}, function(keywordsResponse) {
    $('#createKeywords').parent().children(0).children(0).hide();
    if (keywordsResponse.RESPONSE == "SUCCESS") {
        $('#createKeywords').html(img);
        $('#getTraffic').parent().children(0).children(0).show();

        $.get(WEB_ROOT+'/process/getTraffic', {}, function(trafficResponse) {
            $('#getTraffic').parent().children(0).children(0).hide();
            if (trafficResponse.RESPONSE == "SUCCESS") {
                $('#getTraffic').html(img);
                $('#getGoogleResults').parent().children(0).children(0).show();

                $.get(WEB_ROOT+'/process/getGoogleResults', {}, function(googleScrapeResponse) {
                    $('#getGoogleResults').parent().children(0).children(0).hide();
                    if (googleScrapeResponse.RESPONSE == "SUCCESS") {
                        $('#getGoogleResults').html(img);
                        $('#resortResults').parent().children(0).children(0).show();

As you can imagine this can get complicated and ugly pretty fast. Does anyone have any suggestions on how I can acomplish something like this?

  • 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-31T00:28:38+00:00Added an answer on May 31, 2026 at 12:28 am
    //setup an object to store the necessary info for each AJAX call
    var setup = [
        {
            url      : WEB_ROOT + '/process/createKeywords',
    
            //the callback will be run before the next AJAX request is made
            callback : function (keywordsResponse) {
                $('#createKeywords').parent().children(0).children(0).hide();
                if (keywordsResponse.RESPONSE == "SUCCESS") {
                    $('#createKeywords').html(img);
                    $('#getTraffic').parent().children(0).children(0).show();
                }
            }
        },
        {
            url      : WEB_ROOT + '/process/getTraffic',
            callback : function () {
                $('#getTraffic').parent().children(0).children(0).hide();
                if (trafficResponse.RESPONSE == "SUCCESS") {
                    $('#getTraffic').html(img);
                    $('#getGoogleResults').parent().children(0).children(0).show();
                }
            }
        }
    ];
    
    //setup a function that recursively calls itself when the current AJAX request comes back successfully
    function doAJAX(index) {
        var val = setup[index];
        $.getJSON(val.url, function (serverResponse) {
    
            //run the specified callback for this AJAX request
            val.callback(serverResponse);
    
            //now check if the response is "SUCCESS" and make sure that another AJAX request exists in the `setup` object
            if (serverResponse.RESPONSE == 'SUCCESS' && typeof setup[(index + 1)] != 'undefined') {
    
                //since the last AJAX request was a success and there is another one set, run it now
                doAJAX(index + 1);
            }
        });
    }
    
    //run the first AJAX request by passing in zero (index)
    doAJAX(0);
    

    This just allows you to setup the necessary variables for your consecutive AJAX requests. The callback associated with each url will run before the next AJAX request is run.

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

Sidebar

Related Questions

I am working on a php that application that uses ajax. On all the
I'm currently working on a PHP application that uses a MySQL database for its
I am currently working on a web application that uses PHP and MySQL, but
I'm currently working on an application that uses php's simplexml to interpret rss feeds
I'm working on a PHP application that links into the Protx VSP Direct payment
I am working on a PHP application that intends to ease company workflow and
I am currently working on a PHP application that puts me in the desperate
Hey everyone, I'm working on a PHP application that needs to parse a .tpl
I'm working on an online PHP application that has a need for delayed PHP
I am working on a php application which requires that I extract the dates

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.