我有一个 jquery ajax 调用 asp.net Web 服务,但它不工作。我收到一个错误:
isValid 被低估了。
我设置了一个断点,发现代码永远不会到达 Web 服务。查询:
<script src="../jquery-1.7.2.min.js" type="text/javascript"></script>
<script>
function ValidateUserName() {
var isValid;
$.ajax({ type: "POST",
url: "UserNameWebService.asmx/ValidateUserName",
data: "{'strUsername': '" + $("#<%=TextUserName.ClientID%>").val() + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function (data) {
isValid = data;
}
});
return isValid;
}
</script>
网络服务代码:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class UserNameWebService : System.Web.Services.WebService
{
[WebMethod]
public bool ValidateUserName(string strUsername)
{
\\ then return something by logic
谢谢你。