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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:40:02+00:00 2026-06-06T14:40:02+00:00

So I am posting a call to a method that just returns a string

  • 0

So I am posting a call to a method that just returns a string and my post request returns an object with a string in the responseText field, but the d.responseText returns “undefined.”
Anyone know why? I thought it was because it was AJAX but why is does the var d have the correct value?

var d = $.post("/home/status_update", function(data) {return data});
console.log(d);
console.log(d.responseText);
  • 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-06T14:40:03+00:00Added an answer on June 6, 2026 at 2:40 pm

    It’s one of the far most common errors I’m finding here on AJAX requests: many people don’t realize that AJAX is *A*synchronous, you can’t expect that your d variable gets valued because the code continues its execution regardless of the completion of the AJAX request.

    You can use the retrieved value only when the request-response roundtrip has been completed.

    What you have to do is to actually use the returned value inside the function(data), because you are guaranteed that it will be executed only after the value is actually retrieved.

    The other user obtains the same thing by binding the done event, that is fired upon the completion of the AJAX request/response. It’s the same thing coded in a slight different manner.
    The shorthand is:

    var d = $.post("/home/status_update", function(data) {console.log(data);});
    

    Bear in mind that, as a general application architecture, with AJAX requests you cannot expect to use a single function, you will define functions that will manupulate your response upon every AJAX completion.
    Try to think your application in a more “fragmented” way.

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

Sidebar

Related Questions

I'm trying to make a post call to an action method in MVC 2.
I'm posting an object to an MVC controller. The object contains a field called
Posting this one for a friend. They have an Icefaces app that uses Icefaces's
When posting from JS, PHP (5.3.8) returns some line returns in excess. For example:
Just posting the solution I worked out today. See my answer below. If you
I have a jquery Ajax call function that I use to submit form to
I have a handler /choice with a textarea field and /choicehandler that writes the
I have a client submitting a web-request (POST) of XML data to a server.
I have a BackgroundWorker thread that is posting messages, using BeginInvoke on a textbox
The Facebook Ads API has a call for the posting of ads - and

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.