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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:37:06+00:00 2026-06-11T23:37:06+00:00

Possible Duplicate: How to return the value of a function after the result of

  • 0

Possible Duplicate:
How to return the value of a function after the result of an ajax call has come?

I have one function that use to count the quantity of item in my controller.

function GetQtyItem() {
  var qty;
  var urlQuantity = "Quotation/CountQuantity";
  $.getJSON(urlQuantity, function (quantity) {
      qty = quantity.ja;
  });
  alert(qty); //3
  return qty;
}

I included the file name with the correct part, and called this function in another view of my asp.net mvc project :

<script language="javascript" type="text/javascript">
  var i = GetQtyItem();
  alert(i);
</script>

But the result in the alert dialog is Undefined.

Could any one tell me, how can I alert it with the correct value(3). Thanks in advanced.

  • 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-11T23:37:08+00:00Added an answer on June 11, 2026 at 11:37 pm

    $.getJSON is an AJAX request… which takes time. You must wait for the data to come back, and then alert the result.

    Try this:

    var qty, i;
    function GetQtyItem() {
      var urlQuantity = "Quotation/CountQuantity";
      return $.getJSON(urlQuantity, function (quantity) {
          qty = quantity.ja;
          alert('Request is done');
      });
    }
    
    i = GetQtyItem();
    i.done(function() {
      alert("Quantity is " + qty);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: jQuery: Return data after ajax call success jQuery AJAX: return value on
Possible Duplicate: jQuery ajax return value I have this jQuery script: $('#headerSubmit').click(function() { var
Possible Duplicate: Jquery: Return the value of a ajax call to caller function? In
Possible Duplicate: jQuery: Return data after ajax call success I wrote a script which
Possible Duplicate: Return Value from inside of $.ajax() function I'm working on a CakePHP
Possible Duplicate: return AJAX callback return I have made a JQuery code using AJAX,
Possible Duplicate: c++ virtual function return type I have a simple but confusing question
Possible Duplicate: Access return value from Thread.Start()'s delegate function public string sayHello(string name) {
Possible Duplicate: How to call a JavaScript function from PHP? I have a php
Possible Duplicate: Why can you return from a non-void function without returning a value

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.