Try This Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Runtime.Serialization.Json;
using System.Web.Script.Services;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class WebService : System.Web.Services.WebService
{
public WebService()
{ }
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public CityList GetCities()
{
CityList oBoCityList = new CityList() { new City { Name = "New Delhi", ID = 1 }, new City { Name = "Kanpur", ID = 2 }, new City { Name = "Gurgaon", ID = 3 } };
return oBoCityList;
}
}
public class City
{
public City() { }
public string Name
{ get; set; }
public Int32 ID
{ get; set; }
}
public class CityList : List<City>
{
public CityList() { }
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default5.aspx.cs" Inherits="Default5" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="Script/jquery-1.7.2.min.js"></script>
<script language="javascript" type="text/javascript">
$.ajax({
type: 'POST',
url: 'WebService.asmx/GetCities',
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
error: function(jqXHR, textStatus, errorThrown) {
alert(jqXHR.responseText);
},
success: function(data) {
var cities = data.d;
$.each(cities, function(index, cities) {
alert("City Name: " + cities.Name + "\nID: " + cities.ID);
});
}
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>