用jquery吧(js封装好的方法)。
html
var url = "AccountService.asmx/UserExists";
var userName = $("#txtUserName").val();
$.ajax({
type: "POST",
url: url,
data: '{userName:"'+userName+'"}',
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (json) {
if (json.d == true) {
$("#submit").removeAttr("disabled");
return;
}
$("#submit").attr("disabled", "disabled");
}
});
AccountService.asmx
///
/// 无参数
///
///
[WebMethod]
public string UserExists(string userName)
{
StringBuilder jsonTree = new StringBuilder();
string a = "{name:\"员工1\",Id:10001}";//可以写sql语句从根据userName条件查询数据返回
jsonTree.Append(a);
return jsonTree.ToString();
}