后台代码:
[WebMethod]
public string GetCusCode()
{
DataTable dt = C_c.SelectT("select CusCode from Customer");
string jsonResult = null;
if (dt.Rows.Count > 0)
{
jsonResult = JsonConvert.SerializeObject(dt,Formatting.Indented);
}
return jsonResult;
}
前台代码:
<pre name="code" class="html">$(document).ready(function () {
var rowOption = "";
$.ajax({
type: "post",
contentType: "application/json",
url: "/webservice/WebService.asmx/GetCode",
data: "{}",
dataType: "json",
success: function (data) {
var dt = eval("("+data+")");
alert(dt[0].Code);
for (var i = 0; i < dt.length; i++) {
rowOption += "<option value=" + dt[i].Code + ">" + dt[i].Code + "</option>";
}
$("#cusselect ").empty();
$("#cusselect ").append(rowOption);
}
});
});