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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:39:42+00:00 2026-05-26T20:39:42+00:00

I’m running into an issue with a jquery ajax function not properly returning its

  • 0

I’m running into an issue with a jquery ajax function not properly returning its results back to a javascript if statement.

Here is the issue, we have a database function that is generating a long string of if/then statements, an excerpt of which is below

if(1==1 && (GenericAjaxValidation("System.Yes")=="Y")) {do stuff}

The 1==1 is the result of something that happened in the database, so just ignore that bit. The GenericAjaxValidation call is the piece that is giving us issues The javascript function that it calls is below.

function GenericAjaxValidation(token) {

    $.ajax({
        type: "Post",
        url: '../FormAjax/GetAjaxValResult',
        data: {TOKEN:token,FormId:formDisplay.FormID,FormLayoutId:formDisplay.FormLayoutID},
        dataType: "json",
        timeout: 30000,
        async:false,
        success: function(obj) {
            result=obj.Object.ReturnValue;
        },
        error: function(obj) {

            return false;
        },
        complete: function(){
        return result;
        }
    });

}

The whole process is set up to fire off as part of an onchange event, and we reach the if statement with no issues. If I drop a break point into the jquery ajax function, it processes properly, and returns the “Y” that it is supposed to. However, when I step back out to the if statement, it fails. I looked at it a bit more and realized that it was always treating the result of GenericAjaxValidation as undefined. In fact, to test it, I changed the if statement to test for equality with undefined, and it succeeded.

My suspicion is that while the asynch: false is causing the rest of that single function to wait for the return, it doesn’t appear that the if statement is waiting on it, and evaluates without waiting for the actual value. I searched the net for about a half hour on this one trying to find anything that said for sure one way or the other, but my Google-Fu failed me today.

So, my question is this: is there a way to make this work? or does javascript simply not play nice with this process.

  • 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-26T20:39:43+00:00Added an answer on May 26, 2026 at 8:39 pm

    Try (untested code):

    function GenericAjaxValidation(token) {
        var result
        $.ajax({
            type: "Post",
            url: '../FormAjax/GetAjaxValResult',
            data: {TOKEN:token,FormId:formDisplay.FormID,FormLayoutId:formDisplay.FormLayoutID},
            dataType: "json",
            timeout: 30000,
            async:false,
            success: function(obj) {
                result=obj.Object.ReturnValue;
            },
            error: function(obj) {
    
                result = false;
            }
        });
        return result;
    }
    

    (edit: as @toby pointed out, the complete handler is unnecessary and doesn’t do anything)

    The problem is that GenericAjaxValidation wasn’t returning anything. It’s the complete function that returns. A return only returns from the immediate function, not the enclosing function, so GenericAjaxValidation was just completing without a return

    To make it more clear, your original code could be written to be functionally equivilent like this (note in this sample and your original code, result is a global variable)_:

    function GenericAjaxValidation(token) {
        $.ajax({
            type: "Post",
            url: '../FormAjax/GetAjaxValResult',
            data: {TOKEN:token,FormId:formDisplay.FormID,FormLayoutId:formDisplay.FormLayoutID},
            dataType: "json",
            timeout: 30000,
            async:false,
            success: onSuccess,
            error: onError,
            complete: onComplete
        });
        //No return statement
    }
    function onSuccess(obj) {
        result=obj.Object.ReturnValue;
    }
    function onError(obj) {
        return false;
    }
    function onComplete(){
        return result;
    }
    

    As you can see, GenericAjaxValidation never returns anything.

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

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I need a function that will clean a strings' special characters. I do NOT
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I want to construct a data frame in an Rcpp function, but when I

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.