jQuery中ajax调用当前页面方法
$.ajax({ type: 'POST', url: 'AddressManager.aspx/GetProvince',//AddressManager.aspx当前页面 data: '{cache:0}', dataType: 'json', contentType: 'application/json; charset=utf-8', cache: false, async: false, success: function (data) { var arr = data.d; $("#selProvince").empty(); $("#selProvince").append("<option selected='selected' value=''>省</option>"); for (var i = 0; i < arr.length ; i++) { $("#selProvince").append($("<option></option>").val(arr[i]).html(arr[i])); } $("#selCity").empty(); $("#selArea").empty(); $("#selCity").append("<option selected='selected' value=''>市</option>"); $("#selArea").append("<option selected='selected' value=''>区</option>"); }, error: function (event, request, settings) { // window.location.reload(); } });
[WebMethod] public static List<string> GetProvince(int cache) { ProvinceCityAreaBLL provinceCityAreaBLL = new ProvinceCityAreaBLL(); DataSet ds = provinceCityAreaBLL.GetProvince(); List<string> list = ds.Tables[0].AsEnumerable().Select(x => x.Field<string>("province")).ToList(); return list; }