迈出第一步,尝试一起使用所有这些技术。.我遇到了一些麻烦。.
这是我的服务器端:
[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
公共字符串simplestMethod()
{
返回“返回的最简单方法”;
}
这是我的客户端:
$(document).ready(function(){
$(“ a”)。click(function(event){
$ .ajax({
输入:“ POST”,
网址:“ http:// localhost:53346 / d2 / TAPI.asmx / simplestMethod”,
数据:“ {}”,
contentType:“ application / json; charset = utf-8”,
dataType:“ json”,
成功:功能(数据){
警报(data.d);
},
错误:函数(XMLHttpRequest,textStatus,errorThrown){
alert(“发生错误!” +“ |” + XMLHttpRequest +“ |” + textStatus +“ |” +
errorThrown);
}
});
});
});
结果是一条警告,提示:
发生错误!| [对象XMLHttpRequest] | parseerror | 未定义。
什么解析失败,为什么?
我应该提到直接调用WS方法确实有效。
非常感谢!