【发布时间】:2018-06-11 09:22:12
【问题描述】:
我正在尝试调用一个网络函数,但我不知道我是否犯了任何错误。 这是函数:
[WebMethod]
public string NumberOfHazardsToUser(string userid)
{
JavaScriptSerializer json = new JavaScriptSerializer();
command.CommandText = "select count(*) from Users_Hazards where User_ID = '" + userid + "'";
command.Connection.Open();
SqlDataReader reader = command.ExecuteReader();
if (reader.Read())
{
if ((int)reader.GetValue(0) != 0)
{
int count = (int)reader.GetValue(0);
command.Connection.Close();
return json.Serialize(count);
}
}
command.Connection.Close();
return json.Serialize(0);
}
这就是我的称呼
function getCountHazardsToUser() {
$.ajax({
async: true,
url: web + "/NumberOfHazardsToUser",
method: "GET",
data: '{"userid":"' + localStorage.getItem("id") + '"}',
dataType: "json",
contentType: "application/json",
success: function (data) {
var res = data.d;
hazardsNumber = res;
},
error: function () {
hazardsNumber = -1;
}
});
}
这就是回应 System.InvalidOperationException:缺少参数:用户 ID。
【问题讨论】:
标签: javascript c# ajax web-services