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

The Archive Base Latest Questions

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

Possible Duplicate: jQuery Ajax always returns “undefined”? I’m trying to come up with a

  • 0

Possible Duplicate:
jQuery Ajax always returns “undefined”?

I’m trying to come up with a generic jquery ajax function which takes the url & parameters and returns the result. I’m trying to avoid using async:false as it locks up the browser. If I use success callback in the ajax call, the data returned is null due to the timing issue (success doesn’t wait until the data is returned). If I use complete, the persons object is still null in the LoadPersons method as it doesn’t wait for the data to be returned from the ajax call. If place an alert(persons) in the complete callback, I get [object][Object] so I’m getting the data back. How do I “fix” this issue? Am I talking sense? I would also ideally like to show a “loading..” image while it’s doing this.

Here’s my code –

  <script type="text/javascript">
    $(function() {
                var persons;
                var urlGetPersons = "Default.aspx/GetPersons";

                LoadPersons();

                function LoadPersons() {
                    persons = CallMethod(urlGetPersons, { });
                    if (persons != null) {
                        // do something with persons.
                    }
                }

                function CallMethod(url, parameters) {
                    var data;
                    $.ajax({
                        type: 'POST',
                        url: url,
                        data: JSON.stringify(parameters),
                        contentType: 'application/json;',
                        dataType: 'json',
                        success: function(result) {
                            data = result.d;
                        }, // use success?
                        complete: function(result) {
                            data = result.d;
                        } // or use complete?
                    });
                    return data;
                }
            });
   </script>
  • 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-30T00:28:26+00:00Added an answer on May 30, 2026 at 12:28 am

    This is what’s comes to my mind with “generic” – but it’s still asynchronous:

    function CallMethod(url, parameters, successCallback) {
                    //show loading... image
    
                    $.ajax({
                        type: 'POST',
                        url: url,
                        data: JSON.stringify(parameters),
                        contentType: 'application/json;',
                        dataType: 'json',
                        success: successCallback,
                        error: function(xhr, textStatus, errorThrown) {
                            console.log('error');
                        }
                    });
                }
    
    CallMethod(url, pars, onSuccess);
    
    function onSuccess(param) {
        //remove loading... image
        //do something with the response
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: jQuery ajax error function I am trying to replace a global ajax
Possible Duplicate: jQuery: How to stop AJAX function escaping JSON string used to POST
Possible Duplicate: jquery validate & ajax.beginform I'm trying to use the jQuery validate plugin
Possible Duplicate: jQuery : simulating a click on a <input type=“file” /> doesn't work
Possible Duplicate: using jquery $.ajax to call a PHP function I need to call
Possible Duplicate: Passing JavaScript Array To PHP Through JQuery $.ajax I'm trying to pass
Possible Duplicate: jquery/ajax load new content when available i have a table named news
Possible Duplicate: jquery trigger - ‘change’ function I have a radio button set called
Possible Duplicate: In JavaScript can I make a “click” event fire programmatically for a
Possible Duplicate: Kill Ajax requests using JavaScript using jQuery Here is the simple code

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.