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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:27:04+00:00 2026-06-15T20:27:04+00:00

FIXED! THANKS! See Corrected Code below. The goal is to get data back from

  • 0

FIXED! THANKS! See “Corrected Code” below.

The goal is to get data back from the dialog box. I have seen lots of articles, but could not get any of them to work, so I decided to use a web service to pass the data back and forth between the dialog box and the underlying page.

All of the code is in place except the code that reads values coming back from the web service. I can see in the debugger that the data is being passed back, but when I return to the caller, the returned data is undefined.

jQuery function getLocal calls AJAX, gets good data back, but when it returns to the function that calls it (verbListShow), the returned value is “undefined”.

This is all happening in an ASP.NET page that is written largely in jQuery, and opens a jQuery dialog box.

function getLocal(name) {
    $.ajax({
        type: "POST",
        async: false,
        url: "WebServices/FLSAService.asmx/GetLocalVariable",
        dataType: 'json',
        contentType: 'application/json; charset=utf-8',
        data: JSON.stringify({ name: name }),
        success: function (data) {
            var rtn = data.d;
            return rtn;
        }
    });
}

The above code works, but when called, rtn is undefined. Here is the caller:

function verbListShow(dutyNumber) {

    $('#dlgDutyList').dialog({
        modal: true,
        show: "slide",
        width: 250,
        height: 250,
        open: function (event, ui) {
            setLocal("DUTYNUMBER", dutyNumber);
        },
        buttons: {
            "Select": function () {
                var id = getLocal("VERBID"); // <*** Returns undefined
                var verb = getLocal("VERB"); // <*** Returns undefined
                $.ajax({
                    type: "POST",
                    async: false,
                    url: "WebServices/FLSAService.asmx/SetDuty",
                    dataType: 'json',
                    contentType: 'application/json; charset=utf-8',
                    data: JSON.stringify({ dutyNum: dutyNumber, id: id, verb: verb }),
                    success: function (data) {
                        data = $.parseJSON(data.d);
                        if (data.ErrorFound) {
                            showMessage(data.ErrorMessage, 2, true);
                        }
                        else {
                            log('Set Duty: ' + data.StringReturn + ' (' + data.intReturn + ')');
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        alert("updateDuty: "
                            + XMLHttpRequest.responseText);
                    }
                });

                $(this).dialog("close");
            },
            Cancel: function () {
                $(this).dialog("close");
            }
        }

    });
    $('#dlgDutyList').dialog('open');

FIXED CODE:

function getLocal(name) {
var rtn = "";
    $.ajax({
        type: "POST",
        async: false,
        url: "WebServices/FLSAService.asmx/GetLocalVariable",
        dataType: 'json',
        contentType: 'application/json; charset=utf-8',
        data: JSON.stringify({ name: name }),
        success: function (data) {
            rtn = data.d;
        }
    });
return rtn;
}
  • 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-15T20:27:06+00:00Added an answer on June 15, 2026 at 8:27 pm

    It defeats the purpose of AJAX to use it synchronously (AJAX stands for Asynchronous Javascript And Xml).

    Now you cannot return a value from the success method, but you can store it in a variable and then return that

    function getLocal(name) {
        var returnValue;
        $.ajax({
            type: "POST",
            async: false,
            url: "WebServices/FLSAService.asmx/GetLocalVariable",
            dataType: 'json',
            contentType: 'application/json; charset=utf-8',
            data: JSON.stringify({ name: name }),
            success: function (data) {
                returnValue = data.d;
            }
        });
        return returnValue;
    }
    

    But the proper way would be to use a deferred object

    function getLocal(name, resultset) {
        return $.ajax({
            type: "POST",
            url: "WebServices/FLSAService.asmx/GetLocalVariable",
            dataType: 'json',
            contentType: 'application/json; charset=utf-8',
            data: JSON.stringify({ name: name }),
            success: function (data) {
                resultset[name] = data.d;
            }
        });
    }
    

    and call it

    "Select": function() {
        var results = {};
        var self = this;
        $.when(getLocal("VERBID", results), getLocal("VERB", results)).then(function(){
            $.ajax({
                type: "POST",
                url: "WebServices/FLSAService.asmx/SetDuty",
                dataType: 'json',
                contentType: 'application/json; charset=utf-8',
                data: JSON.stringify({
                    dutyNum: dutyNumber,
                    id: results.VERBID,
                    verb: results.VERB
                }),
                success: function(data) {
                    data = $.parseJSON(data.d);
                    if (data.ErrorFound) {
                        showMessage(data.ErrorMessage, 2, true);
                    }
                    else {
                        log('Set Duty: ' + data.StringReturn + ' (' + data.intReturn + ')');
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert("updateDuty: " + XMLHttpRequest.responseText);
                }
            });
        }).always(function(){
            $(self).dialog("close");
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Thanks for the response, @ManselUK Fixed this part with finding values(below) But , when
I have a fixed data which will be used in a UITableView later and
EDIT: the code below has been fixed to receive and send properly AND to
I have integrated Facebooks Comment box into my page. I copied the generated code
I am a newbie to VBS scripting. Thanks for all your comments! I fixed
EDIT: I have fixed all but two warnings now, so thank you all for
I have a centred fixed width content div , and if there isnt enough
I have a fixed footer on my site here: http://starprovisions.com/dev/bacchanalia.html On my 1360x768 screen
I have three fixed width integer types: typedef int16_t TABCellManagedDataKey; typedef int16_t TABCellManagedDataIndex; typedef
I have code working on all desktop brosers, but in mobile it has a

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.