新手求教,jQuery ajax传值给后台问题
js代码:
$("#btn").mousedown(function () {
var username = "123";
$.ajax({
type: "post",
url: "WebForm.aspx/test",
data: "username=" + username,
contentType: "application/json",
success: function (msg) {
alert(msg);
}
});
});
C# 后台代
[WebMethod]
public static string test(string username)
{
return username;
}
加断点调试发现,在js代码中运行了 var username = "123";这句后再运行 $.ajax,然后就结束了,根本就没有进到后台test这个函数中来。