3
webmethod를 호출하여 select 태그를 채 웁니다. 성공 반환하지만 옵션을 선택 여기 jQuery Ajax 웹 메소드 호출?
을 채우지 않는 것은 내 전화function getCities(country2) {
$.ajax({
type: 'POST',
url: 'getCities.aspx/getCitiesArray',
contentType: 'application/json; charset=utf-8',
dataType: "json",
data: "{countryName:'" + (country2) + "'}",
success: function (msg) {
alert(msg);
$("#city").empty().append($("<option></option>").val("[-]").html("select city"));
$("#city").append($("<option></option>").val("Other").html("Not in the List"));
var htm = "";
$.each(msg.d, function() {
$("#city").append($("<option></option>").val(this['Value']).html(this['Text']));
});
},
error: function() {
alert("Ajax Error");
}
});
및 Visual Studio에서의 WebMethod입니다 2005 ASP.NET 2.0
[WebMethod]
public static ArrayList getCitiesArray(string countryName)
{
ArrayList emptyArrayList = new ArrayList();
string sql = "select ISNULL(CityName,'-') as CityName, ISNULL(CityCode,1) as CityCode from ListCities where CountryID = (select ISNULL(CountryID,0) from ListCountries where CountryName = '" + countryName + "')";
DataTable dtCities = new DataTable();
dtCities = DBUtils.GetDataTable(sql);
ArrayList lstArrCities = new ArrayList();
if ((dtCities != null) && (dtCities.Rows.Count > 0))
{
for (int i = 0; i < dtCities.Rows.Count; i++)
{
lstArrCities.Add(new ListItem(dtCities.Rows[i]["CityName"].ToString(), dtCities.Rows[i]["CityCode"].ToString()));
}
return lstArrCities;
}
return emptyArrayList;
}
당신은 여전히 Visual Studio 2005 with ASP.NET 2.0을 사용하고 있습니까? 정말?????? – frenchie
이 질문과 내가 http://stackoverflow.com/questions/18244696/how-to-return-json-with-asp-net-jquery와 의견에 링크 된 질문을 썼는지보십시오. – frenchie
AJAX 호출에서 돌아올 때 msg의 값은 무엇입니까? – sakir