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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:32:01+00:00 2026-06-08T07:32:01+00:00

I want to call a JSON method on my textbox change event using jquery.

  • 0

I want to call a JSON method on my textbox change event using jquery.

Below is how my JsonResult method looks like

public JsonResult GetUserName(string emailId)
{
    string UserName = "";
    var query = (from u in DbContext.Users
                 where u.User_Email.ToLower() == emailId.ToLower()
                 select u).SingleOrDefault();
    if(query!=null)
    {
        UserName = query.User_FirstName +", "+query.User_LastName;
    }
    return Json(UserName, JsonRequestBehavior.AllowGet);
}

below is my view code

Email:&nbsp;<input type="text" id="txtEmail" /><br /><br />
Name:&nbsp;<input type="text" id="txtName" />

below is the jquery code

<script type="text/javascript">
        $(document).ready(function () {
            //$("#txtEmail").first().focus();

            $("#txtEmail").change(function () {
                var emailId = $(this).val();
                //$("#txtName").val(emailId);
                $.ajax({
                    url: 'GetUserName',
                    type: 'POST',
                    data: JSON.stringify({ emailId: emailId }),
                    dataType: 'json',
                    contentType: 'application/json',
                    success: function (data) {
                        if (data != "" || data != null) {
                            $("#txtName").val(data);
                        }
                        else {
                            alert("Our system does not recognize this email. Please try again.");
                            $("#txtEmail").focus();
                        }
                    }
                });
            });
        });
    </script>

Note….My GetUserName JsonResult method belongs to my Default Controller.

My jquery code is successfully getting executed on change event but the GetUserName method doesn’t get called…please let me know what I am missing.

Thanks,

  • 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-08T07:32:02+00:00Added an answer on June 8, 2026 at 7:32 am

    You url is wrong it should be like /DefaultControllerName/GetUserName (it doesn’t matter that this is the default controller if GetUserName is not the default action you have to specify the contoller in the url) that’s why you should always use the built in UrlHelper to generate the urls in ASP.NET MVC:

    $.ajax({
       url: '@(Url.Action("GetUserName"))',
       type: 'POST',
    

    With the aspx viewengine:

    $.ajax({
        url: '<%: Url.Action("GetUserName") %>',
        type: 'POST'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the below json call in my javascript method function go123(){ var
I am using asp.net mvc with jquery... I have made a json call to
I want to use jackson json library for a generic method as follows: public
I want to make call to authenticate user and get back token in json
I want to call a webservice using google closures, via jsonp since i am
i want to call the command prompt command using Process.Start and then using StandardOutput
I want to call a method say success(message) of javascript from android activity. I
I want to call a web service method in javascript. (asp.net 3.5) I have
I am using a RESTfull webservice with this methode: @POST @Consumes({application/json}) @Path(create/) public void
How would you access the cache from a jQuery ajax call? I'm using jquery

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.