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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:24:51+00:00 2026-06-02T23:24:51+00:00

i am trying to do a ajax get request in asp.net mvc 3. It

  • 0

i am trying to do a ajax get request in asp.net mvc 3. It does not work though ie the GetSquareRoot action is not hit?

index.cshtml

   @{
    ViewBag.Title = "Home Page";
}
<h2>@ViewBag.Message</h2>
<p>
    To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">
        http://asp.net/mvc</a>.
</p>
<script type="text/javascript">
        function calculateSquareRoot(numberToCalculate) {
            $.ajax({
                type: 'Get',
                url: '/Home/GetSquareRoot',
                data: { number: numberToCalculate },
                success: function (data) { alert(data.result); }
            });
        }

</script>
<button onclick="calculateSquareRoot(9);">Calculate Square</button>

on the homecontroller:

public JsonResult GetSquareRoot(long number)
{
    var square = Math.Sqrt(number);
    return Json(new { result = square }, JsonRequestBehavior.AllowGet);
}
  • 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-02T23:24:56+00:00Added an answer on June 2, 2026 at 11:24 pm

    If I mount the following page on localhost:

    <!DOCTYPE html>
    <html>
        <head>
            <script type="text/javascript" 
               src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js">
            </script>
            <script type="text/javascript">
            //<![CDATA[
                function calculateSquareRoot(numberToCalculate) {
                    $.ajax({
                        type: 'GET',
                        url: '/Home/GetSquareRoot',
                        data: { number: numberToCalculate },
                        success: function (data) { alert(data.result); }
                    });
                }
            //]]>
            </script>
        </head>
        <body>
            <button onclick="calculateSquareRoot(9);">Calculate Square</button>
        </body>
    </html>
    

    When I hit the button, I see a request issued to:

    http://localhost/Home/GetSquareRoot?number=9
    

    Are you sure you’ve told us the whole story?

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

Sidebar

Related Questions

I am trying to mock the Ajax.IsRequest() method of ASP.Net MVC. I found out
I'm trying to get ASP.Net to cache the response of a web service request
While trying to GET a JSON, my callback function is NOT firing. $.ajax({ type:GET,
I am using asp.net mvc, C# and jquery. My site is uses ajax heavily.
We have been wrestling with the confines of ASP.NET trying to get JSONP working.
I've been trying to get some Ajax stuff to work in my Django application,
I am using Asp.net MVC3 and trying to do a simple Ajax post to
I am trying to create a simple ajax chat using JQuery and ASP.NET. My
I'm trying to send the node instance JSON data using an ajax get request
I'm trying to create a page using ASP.NET MVC 2 which shows two things:

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.