【发布时间】:2014-05-17 22:02:13
【问题描述】:
我试图从 Ajax 代码调用方法,而我的 ajax 代码根本无法进入该方法。 我的代码有什么问题?
C#方法:
[WebMethod]
public static bool UserNameExists(string sendData)
{
bool a;
a = DataCheck.CheckDBUser(sendData);
return a;
}
阿贾克斯:
$('#Button2').click(function () {
var name = document.getElementById('<%= UserTxt.ClientID %>').value;
$.ajax({
type: 'POST',
url: 'Register.aspx/UserNameExists',
data: '{ }',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function(msg) {
if (msg.d == true) {
$("#UserLb").text("User Name is OK!");
} else {
$("#UserLb").text("User Name NOT avliable!");
}
}
});
});
注意:当我使用 alert();命令只是为了检查它是否正在运行 - 没问题。
谢谢。
【问题讨论】:
标签: c# javascript jquery ajax