Monday, October 29, 2012

Dynamically Loading a Dropdown with JSON data

function getstate(countryId) {
$.ajax(
{ type: "POST",
url: "OfficeData.asmx/Getstates",        
data: "{'countryId':" + (countryId) + "}",        
contentType: "application/json;
charset=utf-8",        
global: false,
async: false,        
dataType: "json",        
success: function(jsonObj)
{            
var listItems= "";
var jsonData = jsonObj.d;    
for (var i = 0; i < jsonData.Table.length; i++)
{
listItems+= " + jsonData.Table[i].statename + "
"; }    
$("#<%=DLState.ClientID%>").html(listItems); //DLState is the dropdown

No comments: