【问题标题】:Get "Invalid web service call, missing value for parameter" error when calling a web service method using jQuery使用 jQuery 调用 Web 服务方法时出现“无效的 Web 服务调用,缺少参数值”错误
【发布时间】:2010-09-20 20:27:56
【问题描述】:

这是我的 aspx 文件代码:


var DTO = { "'productCategoryId'": "'10'" };
$.ajax({
 type: "GET",
 url: "/WebService/DsmWebServices.asmx/GetProductSubCategory",
 data: DTO,
 contentType: "application/json; charset=utf-8",
 dataType: "json",
 success: function (msg) {
  window.alert("success");
 },
 error: function (msg) {
 }
});

这是我的网络服务方法:


[WebMethod,ScriptMethod(UseHttpGet=true)]
public bool GetProductSubCategory(int productCategoryId)
{
 //do some stuff
 return true;
}

问题是jQuery函数失败并出现以下错误:


{"Message":"Invalid web service call, missing value for parameter:
\u0027productCategoryId\u0027.","StackTrace":"   at System.Web.Script.Services.WebServiceMethodData.CallMethod(Object target, IDictionary`2 parameters)\r\n   at
System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary`2 parameters)\r\n   at
System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n   at
System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"}

通过使用 Firebug,jQuery 请求的 URL 是


http://192.168.1.100:8888/WebService/DsmWebServices.asmx/GetProductSubCategory?%27productCategoryId%27=%2710%27

【问题讨论】:

  • 为什么"'10'" 周围有多余的引号? (实际上使它不是整数....)

标签: asp.net jquery web-services asp.net-ajax


【解决方案1】:

您必须在 ajax 调用中使用“post”作为类型。此外,传递给 Web 服务的数据需要是 json 字符串。不是 json 对象。看一下json2库的stringify方法:

http://www.json.org/js.html

【讨论】:

    【解决方案2】:

    在其他错误消息中,我收到了相同的消息。由于我确实最终使用了帖子,我想向读者指出我的另一个答案:Calling Webservice with Jquery causing woe

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-05
      • 2011-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-28
      • 1970-01-01
      相关资源
      最近更新 更多