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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:02:09+00:00 2026-05-17T03:02:09+00:00

I have a JSON request that check to the server if a username has

  • 0

I have a JSON request that check to the server if a username has been already taken during the registration procedure.

This is the jQuery call:

// Instant check availability of the username
$("#txtUserName").blur(function() {
    if ($("#txtUserName").val() == "") return;
    $.ajax({
        type: 'post',
        url: '/Login/CheckUserName',
        data: "{userName: '" + $("#txtUserName").val() + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(message) {
            //Set the spanChecking text letting user know if the uname is available
            if (message.d == true) {
                $("#userNameCheck").css({ "color": "red", "font-weight": "bold", "font-size": "small", "padding-left": "5px" });
                $("#userNameCheck").text("Non disponibile");
            }
            else {
                $("#userNameCheck").css({ "color": "green", "font-weight": "bold", "font-size": "small", "padding-left": "5px" });
                $("#userNameCheck").text("Disponibile");
            }
        },
        error: function(errormessage) {
            //this is just to see if everything is working. Remove before deploy
            $j("#userNameCheck").text(errormessage.responseText);
        }
    });
});

and this is the controller action that will serve the request

[HttpPost]
public JsonResult CheckUserName( string userName ) {
    if ( Membership.GetUser( userName ) == null )
        return Json(false);
    else
        return Json(true);
}

Anyway I dont understand why I am getting error 500 from the server. Looking at it with Fiddler I can see that the RAW request is

POST http://localhost:1037/Login/CheckUserName HTTP/1.1
Host: localhost:1037
Connection: keep-alive
Referer: http://localhost:1037/Login/Register
Content-Length: 22
Origin: http://localhost:1037
X-Requested-With: XMLHttpRequest
Content-Type: application/json; charset=UTF-8
Accept: application/json, text/javascript, */*
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.63 Safari/534.3
Accept-Encoding: gzip,deflate,sdch
Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

{userName: 'sampleuser'}

but the controller Action receive a null parameter for userName. I see this through Fiddler and even putting a breakpoint on the code.

Where am I doing wrong?

EDIT

The error returned back to the client is

The value cannot be null. Parameter name: username

Please note that the parameter Name in the error is not preserving the original case. Is this a behaviour of the membership provider or should I lower the case of the parameter?

  • 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-05-17T03:02:10+00:00Added an answer on May 17, 2026 at 3:02 am

    You are sending the request as JSON but there’s nothing in the server that understands or expects this format. You have a controller action which expects application/x-www-form-urlencoded content type. Try this instead:

    data: { userName: $('#txtUserName').val() },
    contentType: 'application/x-www-form-urlencoded',
    

    This also has the advantage to take care of properly url encoding the parameters sent to the server which in your version using string concatenations wasn’t achieved.

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

Sidebar

Related Questions

I have an jQuery JSON request, that loads some JSON from another server (ex.
I have JSON string that has nested objects with dynamic names that vary each
I have JSON text that looks like this: { ok: true, totalPages: 256, arReports:
I have a couple of app engine urls that return pure JSON and this
I have a registration form for a website that needs to check if an
I have a portion of my site that has a lightweight xml/json REST API.
I don't have any idea how to post a JSON RPC request using Obj-C.
I have a php function which returns JSON in response to a ajax request
I have JSON like this: { something: http://something.com } and HTML like this: <a
i have json data like this {GetStudentDetails: {TotalCount:5, RootResults:[ {city:West Chester,country:USA,state:PA ,student_id:100}, {city:Philly,country:USA,state:PA,student_id:101}, {city:Buffalo,country:USA,state:NY,student_id:102},

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.