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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:09:59+00:00 2026-06-18T01:09:59+00:00

I have a function that loops through a multidimensional array that consists of the

  • 0

I have a function that loops through a multidimensional array that consists of the id of an area on my webpage and then a parameter that I have to pass to a webservice. The return from the $.ajax() call will be HTML that I wish to populate (repaint) within the first part of the array:

function getViews(){

    // loop through, need view/jsp name and where we want to put the HTML... need a multidimarray...
    var viewArr = [["infoCol","info"], 
                   ["noteCol", "notes"],
                   ["buttonsDiv", "buttons"],
                   ["historyPanel","history"], 
                   ["servicesPanel","services"],
                   ["noFOUC","dialogs"]
                  ];

    // do the loop
    for(var i = 0;i<viewArr.length;i++){

        var thisArea = viewArr[i][0];

        $.ajax({
            url:"getView",
            type:"POST",
            data:{view:viewArr[i][1]},
            dataType:"html",
            success:function(data){
              console.log(thisArea); // this is always noFOUC
              // console.log(viewArr[i][0]); // this gives an undefined error...
                $("#" + thisArea).html(data);
            },
            error:function(xhr, ajaxOptions, thrownError){
                console.log(xhr.status);
                console.log(xhr.statusText);
                console.log(thrownError);
            }
        }); 

    }
}

Now all is well however trying to reference the first part of the loop viewArr[i][0] within the success: callback isn’t working! If I place it within the success: it is undefined. If I give it a var outside the $.ajax() like in the example above it is always the last item of the array! I’m sure I need to add a closure here but I’m not sure where or why, can someone please explain?

If I haven’t worded or explained this well please let me know and I will explain better.

  • 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-18T01:10:00+00:00Added an answer on June 18, 2026 at 1:10 am

    dI think I have this… I placed a self execution function inside the loop… forgot about asynchronous! The loop continues… doh!

    function getViews(){
    
        // loop through, need view/jsp name and where we want to put the HTML... need a multidimarray...
        var viewArr = [["infoCol","info"], 
                       ["noteCol", "notes"],
                       ["buttonsDiv", "buttons"],
                       ["historyPanel","history"], 
                       ["servicesPanel","services"],
                       ["noFOUC","dialogs"]
                      ];
    
        // do the loop
        for(var i = 0;i<viewArr.length;i++){
    
            (function(){
    
            var thisArea = viewArr[i][0];
            $.ajax({
                url:"getView",
                type:"POST",
                data:{view:viewArr[i][1]},
                dataType:"html",
                success:function(data){
                    $("#" + thisArea).html(data);
                },
                error:function(xhr, ajaxOptions, thrownError){
                    console.log(xhr.status);
                    console.log(xhr.statusText);
                    console.log(thrownError);
                }
            }); 
    
            })(viewArr[i][0]);
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function here that loops through two wrappers and then loops through
I have written this code that loops through an array of lat/long coordinates and
I have a function that loops through different types of listings pulled from MySQL
I have created a function that loops through a set of returned JSON. I
I have a form validation function that loops through the form elements checking for
I have a function that gets some notifications, loops through them and the adds
I have the following snippet of code that loops through the jQuery animate function
I have a function that is called on document.ready that loops through a table
I have a function that loops through my list of objects, makes some checks
I have a callback function for another function that loops through the comments of

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.