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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:31:12+00:00 2026-05-27T20:31:12+00:00

I have a pretty complicated function which does a couple of AJAX posts on

  • 0

I have a pretty complicated function which does a couple of AJAX posts on submitting a form, to verify values. Depending on the values returned from the POSTs the submit should either work or fail. I thought this could be done using a global boolean and setting its value to either true or false throughout the function, then checking at the end if the boolean had been changed to ‘true’ and if so call ‘return false;’.

This is failing though. I’ve read up around it and I think it’s because the AJAX call is asynchronous so the code isn’t executed in sequence.

My code is like this:

  $('.to-step-3').click(function(){
var shape = '';
blnError = false;
$.post('/base/RoomBuilder/GetRoomShape.aspx', function(data) {
  if(data.substring(0,5) == 'Error'){
    alert(data);
    blnError = true;
  }else{
    shape = data;

    $.post('/base/RoomBuilder/GetRoomDimensions.aspx', function(data2) {
      if(data2.substring(0,5) == 'Error'){
        alert(data2);
        blnError = true;
      }else{
        var arrDims = data2.split('_');
        var l =  arrDims[0];
        var w =  arrDims[1];
        var sl = arrDims[2];
        var ll = arrDims[3];
        var sw = arrDims[4];
        var lw = arrDims[5];
        var failMessage = 'Please enter all required dimensions to build your room';

        switch(shape) {
          case 'square':
            if(!(notNullOrEmpty(l))){
              alert(failMessage);
              blnError = true;
            }
          break;
          case'rectangle':
            if(!(notNullOrEmpty(l)) || !(notNullOrEmpty(w))){
              alert(failMessage);
              blnError = true;
            }
          break;
          case'lshaped':
            if(!(notNullOrEmpty(sl)) || !(notNullOrEmpty(ll)) || !(notNullOrEmpty(sw)) || !(notNullOrEmpty(lw))){
              alert(failMessage);
              blnError = true;
            }
          break;
          case'lshapedalt':
            if(!(notNullOrEmpty(sl)) || !(notNullOrEmpty(ll)) || !(notNullOrEmpty(sw)) || !(notNullOrEmpty(lw))){
              alert(failMessage);
              blnError = true;
            }
          break;
        }
      }
    });


  }
});

if(blnError == true){
  return false;
}else{
  return true;
}

});

I found an example of something similar jquery – return value from callback function (in post request) into the function its inside of? but am struggling to get my head around it in the context of what I need to do (I’m admittedly not great at Javascript!)

Could anyone please point me in the right direction here as I’ve been staring at this way too long! Thanks all.

  • 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-27T20:31:12+00:00Added an answer on May 27, 2026 at 8:31 pm

    jQuery post is async by nature so before the ajax response comes the if condition has already been executed. If you want to make execution wait untill ajax response comes then you can use jQuery ajax setting async property to false. Try this

    $.ajax({
       url: '/base/RoomBuilder/GetRoomDimensions.aspx',
       async: false,
       type: 'post',
       success: function(){
           //Your logic here
       }
    });
    
    //Now check the condition here
    if(blnError == true){
      return false;
    }else{
      return true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a function which does something pretty complicated and it is
i have a pretty complicated form. as you can see below: alt text http://img9.imageshack.us/img9/2465/test2xk.jpg
I have a function which isn't so complicated, but for some reason, each time
OK. I have a very long and pretty complicated function. It looks almost like
I have a pretty complicated Linq query that I can't seem to get into
I have a pretty complicated index.php now, and I would like to only run
I'm back with another (possibly) silly question. sorry. I have a pretty complicated query
Within JSP files, I have some pretty complicated Javascript. On a production machine, we're
I have pretty complicated listview component organized as table. On every tr line I
I have created a pretty complicated app using some sort of factory design pattern.

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.