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

  • Home
  • SEARCH
  • 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 6948257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:47:53+00:00 2026-05-27T13:47:53+00:00

I have a jquery $.post function lik so: $.post(‘/test’,json_data, function(data) { result=data }); this

  • 0

I have a jquery $.post function lik so:

$.post('/test',json_data, function(data) {
                                result=data
});

this function is actually being used in an validation…So it the return value(data) contains true or false. But this value is not being stored in the variable ‘result’. I understand that this is because post makes an asynchronous call and hence it does’nt wait for the response. What I want to ask is, is there some workaround for this? or can this call be made synchronous somehow??

  • 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-27T13:47:54+00:00Added an answer on May 27, 2026 at 1:47 pm

    This is considered a bad practice but there is an async parameter in $.ajax() that you can set to false and wait synchronously for a result:

    var result;
    $.ajax({
      type: 'POST',
      url: '/test',
      data: json_data,
      async: false,
      success: function(data) {
        result=data;
      },
      dataType: 'application/json'
    });
    //result available here
    

    A more idiomatic, although slightly less convenient in this case, would be to take advantage of callbacks:

    function validate(okCallback, errorCallback) {
        $.post('/test',json_data, function(data) {
            if(data) {
                okCallback();
            } else {
              errorCallback();
            }
        });
    }
    
    validate(
        function() {
            //proceed
        },
        function() {
            //display validation error
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this jQuery script: $(.show-div).data('loaded',false).click(function() { $.post(script.php, {id_1: var_id_1, id_2: var_id_2}, function(data){ $(this).data('loaded',true);
I have written a form using the jQuery .post() function to post the data
I have got jquery post function jQuery('.more-button').live('click', function(eve){ var page = jQuery(this).attr('id').replace('more-button-',''); loaded_messages +=
I have jquery ajax() function: $.ajax({ type: POST, url: 'ajax.php', data: 'url='+variable, success: function(data){
So I have the jquery code here: $(document).ready(function(){ $(div.post.photo).hover(function () { $(this).children(div.show).slideToggle(fast); }); });
I have a function which has a jQuery.post being done, with POST parameters passed
I have a jQuery post function that returns a response on success after the
I have a jQuery script: $.ajax({ url: /scripts/secure/development/ajax.asp, type: POST, dataType: text, data: cmd=addresses,
I have an ASP.NET application in which i want to post data using jQuery
On button click I have the simple jQuery post : $(document).ready(function() { $.post(/cgi-bin/stats.exe); });

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.