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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:13:50+00:00 2026-06-11T08:13:50+00:00

I have a problem passing data from a JQuery ajax call back to the

  • 0

I have a problem passing data from a JQuery ajax call back to the calling location. The code in question is below:

jQuery("#button").click(function()
{   
    for(var i = 0;i < data.length; i++)
    {
        result = updateUser(data[i]); //result is not populated..
                    alert(result); //prints 'undefined'

    }
});

function updateUser(user_id)
{       
    jQuery.ajax({
        url:"/users/update/"+user_id,
        type:"GET",
        async: false,
        success: (function(data){           
            //if I alert "data" here it shows up correctly
                            //but if i try to return it like below 
                            //it does not get passed correctly 
                            return data; 
        })
    });

Any pointers are greatly appreciated

  • 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-11T08:13:52+00:00Added an answer on June 11, 2026 at 8:13 am

    You cannot return value from an AJAX success handler like that. AJAX is asynchronous so execution will proceed to the next line where result is undefined. The only way you can get data back from an asynchronous operation is to use a callback. A callback is a function that gets called when the asynchronous operation finishes what it is doing:

    jQuery("#button").click(function () {
        for (var i = 0; i < data.length; i++) {
            updateUser(data[i], function(result) {
                alert(result);
            });
        }
    });
    
    function updateUser(user_id, callback) {
        jQuery.ajax({
            url: "/users/update/" + user_id,
            type: "GET",
            success: callback
        });
    }
    

    Here, you’re calling the callback in the success handler of the AJAX call and so now you have access to the data that was returned by the AJAX call.

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

Sidebar

Related Questions

I have a problem on going back (clicking the Back button) from sub-activity to
i have problem passing data from one page to another using GET, for example
In my MVC application I have a problem with passing data from view to
I have encountered a problem with passing data from another activity to the current
I have a problem of passing data from one textarea to another textarea on
I have a problem when passing data in .getJSON. The reason for this is
I have problem with passing an argument to my simple function in jQuery: When
I seem to have a problem passing some strings on from one form to
I have a jQuery ajax function that retrieves JSON data. In the success block
I have this problem.. I'm receiving data from a client..Using a socket connection. But

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.