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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:31:03+00:00 2026-06-18T07:31:03+00:00

Hi all I have used the following code to check whether data exists or

  • 0

Hi all I have used the following code to check whether data exists or not

This is my input design

<label>
 @Html.LabelFor(u => u.Username)</label>
<input type="text" id="username" />
 &nbsp;
<label id="UserNameAvailabilityLabel" class="input_text">
</label>
 <span class="input_error">
 @Html.ValidationMessageFor(u => u.Username)
</span>
</label>


<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
var emptyUserNameMessage = 'Please enter the username';
var progressUserNameMessage = 'Checking...';
var availableUserNameMessage = 'Username is available';
var usedUserNameMessage = 'Username has been taken';


$(function () {
    var userNameAvailabilityLabel = $("#UserNameAvailabilityLabel");

    $("#username").blur(function () {
        var userNameTextBox = $("#username");
        var userName = userNameTextBox.val();
        if ($.trim(userName) == '') {
            userNameAvailabilityLabel
                        .removeClass()
                        .addClass('required1')
                        .html(emptyUserNameMessage);
        }
        else {
            userNameAvailabilityLabel.html('');
            $("#ProgressDiv").show();

            $.ajax({
                type: 'POST',
                url: 'Checkavailability.asmx/CheckUserNameAvailability',
                data: '{userName: \'' + userNameTextBox.val() + '\'}',
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                success: OnCheckUserNameAvailabilitySuccess,
                error: OnCheckUserNameAvailabilityError
            });
        }
        return false; //Prevent postback
    });

    function OnCheckUserNameAvailabilitySuccess(response) {
        $("#ProgressDiv").hide();
        if (response != null && response.d != null) {
            var data = response.d;
            switch (data) {
                case 0:
                    userNameAvailabilityLabel
                        .removeClass()
                        .addClass('available')
                        .html(availableUserNameMessage);
                    $("#btnSubmit").removeAttr('disabled');
                    break;
                case 1:
                    userNameAvailabilityLabel
                        .removeClass()
                        .addClass('used')
                        .html(usedUserNameMessage);
                    $("#btnSubmit").attr('disabled', 'disabled');
                    break;
            }
        }
    }
    function OnCheckUserNameAvailabilityError(xhr, ajaxOptions, thrownError) {
        alert(xhr.statusText);
    }
});

This works when I used this in a normal aspx page but when coming to MVC the first script is getting executed means if I move from text box with out entering data it is displaying the error as per required, if enter some text and leave the text box it is giving an popup as Internal server error what might be the problem

  • 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-18T07:31:04+00:00Added an answer on June 18, 2026 at 7:31 am

    just changed url: 'Checkavailability.asmx/CheckUserNameAvailability', to url: "../Checkavailability.asmx/CheckUserNameAvailability",

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

Sidebar

Related Questions

On Blackberry 6.0, I have used the following code to delete all the call
I have the following code to create an NSDictionary and then check if all
I have used all the Standard Network related code for Getting Images of about
All I have used osmdroid and i want to download map zip files from
I have never really used regular expressions all that much and as such i
What all language components will have to be used for implementing an email service
I used to have a simple ajax that helped me take all items from
I have some classes that are used for Styling and all of them display
All the examples I have seen where the PropertyPlaceHolderConfigurer is used seem to be
I have a logger class that is used all across my application, both in

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.