【发布时间】:2019-02-02 20:00:40
【问题描述】:
我有以下 HTML 超链接,我想在点击时在 jQuery 中调用它
<a href="#" data-toggle="dropdown" id="notID" class="dropdown-toggle f-s-14">
<i class="fa fa-bell"></i>
<span runat="server" id="notCount" class="label">5</span>
</a>
当我点击超链接时,会执行以下代码
<script src="assets/plugins/jquery/jquery-1.9.1.js"></script>
<script>
$(document).ready(function () {
$("#notID").click(function () {
var uID = '<%=Session["userID"].ToString() %>'
$.ajax({
url: 'TaskService.asmx/updateNotRead',
data: '{userID: "' + uID + '"}',
type: 'POST',
contentType: 'application/json',
dataType: 'json'
});
return false;
});
});
</script>
在 webservice 文件中,我编写了以下 C# 代码,其中包含我从上面的 jQuery 调用的 webmethod 的定义。
[WebMethod]
public void updateNotRead(string userID)
{
u.updateNotReadStatus(userID);
}
当我调用网络服务时,我在浏览器中收到以下消息
System.InvalidOperationException: Missing parameter: userID.
at System.Web.Services.Protocols.ValueCollectionParameterReader.Read(NameValueCollection collection)
at System.Web.Services.Protocols.UrlParameterReader.Read(HttpRequest request)
at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
那么我怎样才能给 web 方法提供 userID 参数呢?
【问题讨论】: