O'Reilly logo

ASP.NET jQuery Cookbook by Sonal Aneel Allana

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Consuming web services with AJAX

In addition to page methods, jQuery also enables the making of AJAX calls to web services. In this recipe, we will validate the username keyed in by the end user by making a call to a web service instead.

Getting ready

  1. Add a web service UserNameWS.asmx to the current project.
  2. Add the following namespace to the code-behind:
    using System.Web.Services;
    
    
  3. To enable the web service to be called using AJAX, add the following:
    [System.Web.Script.Services.ScriptService]
    
  4. Add a web method to validate the username as follows:
    [WebMethod] public bool CheckUserName(string sUserName) { string[] UserNameArray; UserNameArray = new string[7] { "testid01", "testid02", "testid03", "testid04", "testid05", "testid06", "testid07" }; foreach ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required