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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:07:28+00:00 2026-06-12T19:07:28+00:00

I have the following jQuery code: var isUsernameAvailable = false; function CheckUsername(uname) { $.ajax({

  • 0

I have the following jQuery code:

var isUsernameAvailable = false;

function CheckUsername(uname) {
        $.ajax({
            method: "POST",
            url: "IsUsernameAvailable.asmx/IsAvailable",
            data: { username: uname },
            dataType: "text",
            success: OnSuccess,
            error: OnError
        });     // end ajax
    }   // end CheckUsername
    function OnSuccess(data) {            
        if (data == true) {    // WHY CAN'T I TEST THE VALUE
            isUsernameAvailable = true;
        } else {
            isUsernameAvailable = false;
            $('#error').append('Username not available');
        }
    }
    function OnError(data) {
        $('#error').text(data.status + " -- " + data.statusText);            
    }

And a simple Web Service:

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following     line. 
[System.Web.Script.Services.ScriptService]
public class IsUsernameAvailable : System.Web.Services.WebService {

    public IsUsernameAvailable () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public bool IsAvailable(string username) {
        return (username == "xxx");
    }

}

I just can’t read the return value from my web service. When I print out the value in the callback function (data parameter) I get true or false (note the preceding whitespace).

When I print out data.d, it says undefined. FYI, the web service method gets hit each time.

  • 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-12T19:07:30+00:00Added an answer on June 12, 2026 at 7:07 pm

    You have the dataType specified as text. This would lead me to believe that the response you’re getting is actually a string and not a boolean value. Switching the dataType to json would give you a Javascript object.

    Edit: The reason for the parsererror is because the boolean that you are returning is actually a .NET boolean converted to a string. When .ToString() ends up being called for the actual HTTP response, it ends up being True or False. In JSON, boolean values are true or false (notice the casing). When jQuery is trying to parse the response, it doesn’t think it’s a correct boolean and throws the error.

    Depending on what ASP.NET flavor you are using, you have a few options. If you’re using MVC or the Web API, just return like this:

    return Json(username == "xxx", JsonRequestBehavior.AllowGet);
    

    If you aren’t using either of those technologies, then it might be best to change your return type to a string and then call:

    return new JavaScriptSerializer().Serialize(username == "xxx");
    

    You will need to import the System.Web.Script.Serialization namespace for the previous code snippet to work.

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

Sidebar

Related Questions

I have the following jQuery 1.7.2 code: var theParams = encodeURIComponent(s1)+encodeURIComponent(s2); $.post('/myURL',theParams,processData).error(errorResponse); function processData(data,textStatus){
I have the following jQuery code: $(.save_button).click(function() { var $form = $(this).closest(div.info_section).find(form); url =
I have the following jQuery Code: $(#menu span).click(function() { var url = this.getAttribute(data-url); var
I have the following JQuery code: $(document).ready(function () { var $containerHeight = $(window).height(); if
I have the following jquery code: jQuery(function(){ jQuery(select#rooms).change(function(){ var options = ''; jQuery.getJSON(/admin/selection.php,{id: jQuery(this).val(),
I have the following JQuery code: <script type=text/javascript> $(document).ready(function () { var $containerHeight =
I have the following jQuery code: $('.save').submit(function(e){ var formElement = $(this); var data =
I have the following jquery code: $(.rotateNews).load(/load_news.php); var refreshId = setInterval(function() { $(.rotateNews).load('/load_news.php?newsID='); },
I have the following jQuery ajax call setup: function Testing() { var result =
I have the following jquery code. var destTable = $(#numbers); $(document).ready(function() { $(#btnAdd).click(function() {

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.