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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:49:52+00:00 2026-06-17T04:49:52+00:00

My function below makes and AJAX call and since it is an invalid JSON

  • 0

My function below makes and AJAX call and since it is an invalid JSON object returned I have to manually parse the results into a valid JSON object (which works). The problem is when I am passing the JSON object back to the original calling function the object doesn’t get passed back correctly.

If I only put the third alert in it will say ‘invalid’ for the object. However if I put all three alerts in, only alert 2 will say invalid (1 and 3 will show object). This makes believe it might be some type of timing issue passing the object between these variables. Any recommendations on how to resolve this, as I obviously cannot put alerts in my final code.

    function loadDocuments(){
       var myDocuments = getDocs();
       alert('third response ' + myDocuments);
    }

    function getDocs() {            
            var myURL = "someURL";
            var response;
            $.ajax({
                url: myURL,
                type: 'GET',
                dataType: 'json',
                 complete: function(docData) {
                   if(docData.status==200){
                       response = parseDocResults(docData.responseText);
                       alert('first response' + response);                                                   
                   }else{
                       response = "Documents failed to load";
                   }
                }
            });
            alert('second response' + response);
         return response;
    } 
  • 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-17T04:49:53+00:00Added an answer on June 17, 2026 at 4:49 am

    Using AJAX the way you tried it means using it in a synchronous approach which blocks the browser until the transfer is finished. You can find an async configuration flag for the $.ajax() function which makes the AJAX work synchronous when set to false but I wouldn’t recommend it (and it’s deprecated too).

    The $.ajax() function just sends an HTTP request towards the server. It does not wait for a reply it returns immediately and execution continues with what ever instructions were after the ajax function call.

    Sometime later the browser (JavaScript) receives an HTTP response from the server. Your ajax function call specified a complete/success callback which is used to handle the HTTP response. But since that callback was executed “sometime later” you have to shape your logic from within the callback, without relying on a return value.

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

Sidebar

Related Questions

I have a function that makes an ajax call to get the initial data
Below is my javascript function that makes an ajax call via post. It sends
I have a JavaScript page that makes an Ajax call like the code below.
I have the code below that shows a throbber and makes a getJSON call
The function below will make an Ajax call to load data from a mySQL
I have written below code to make an ajax call using jquery: $.ajax({ url:
I have the below jQuery code: $(document).ready(function () { $('#ajaxButton').click(function () { $.ajax({ url:
Below code makes form to be submitted without html5 validation... $j(document).on(click, #client_entry_add, function(event){ ajax_submit();});
I have the function below. It gets the values from checked boxes and transfer
I have written a function below: void trans(double x,double y,double theta,double m,double n) {

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.