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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:28:24+00:00 2026-06-10T11:28:24+00:00

I am making a simple JSON post to the server and I retrieve just

  • 0

I am making a simple JSON post to the server and I retrieve just on boolean. The problem is that this json call is inside another function which needs to return that boolean as well.

I have two solutions here

  1. Somehow return data from JSON return function and then return it again from wrapper function (the code that I have here doesn’t work, I can’t figure out how to return data from “function(){} inside $.postJSON:

        function testZipCode(zipcode, state) {
        var s;
        $.postJSON("/Cart/ZipTest",
            {
                state: state,
                zipCode: zipcode
            }, function (data) {
                if (!data.ok) {
                    s = false;
                }
                s = true;
            });
            return s;
    }
    

    }

  2. Wait for POST to finish and then return the result like this: (the error I get here is that I call return before POST is finished, thus responseText is null. Can anyone please help?

     var result = $.postJSON("/Cart/ZipTest",
     {
                state: state,
                zipCode: zipcode
            }, function (data) {
                if (!data.ok) {
                    //do something
                }
            });
            return $.parseJSON(result.responseText).ok;
    
  • 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-10T11:28:25+00:00Added an answer on June 10, 2026 at 11:28 am

    Return the ajax call as a deffered object and do something in the callback function:

    function someOtherFunction() {
        testZipCode('90102', 'FL').done(function(data) {
            if (!data.ok) something = false;
        });
    
    }
    
    function testZipCode(zipcode, state) {
        return $.getJSON("/Cart/ZipTest", {state: state, zipCode: zipcode} );
    }​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making this ajax call: $.ajax({ url: /test/whatever, type: 'post', contentType: 'application/json' data:
I'm new to iOS development and I'm having trouble making a simple Json POST
in making a simple cgi server for a course. To do that in some
We're making some calls to some very simple JSON web services in .NET CF
I'm making a simple URL request with code like this: URL url = new
I'm making a simple mediaplayer app that downloads a song from a predetermined URL
I am making a query call to freebase and I receive a JSON response.
Hi I'd like to build a simple json looking like this: {Count : 55,
I'm making a simple javascript app that needs to run locally (on a CD
I have a simple iPhone application I am making that will upload pictures to

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.