我一次又一次地寻找,但没有希望。我开始认为这是一个 IE 10 错误。因为下面的代码适用于 Chrome、Firefox、IE 7 8 9 等。
我收到了这个错误
GetDataFromWebMethod(): {"Message":"Invalid web service call, missing value for parameter: \u0027recordID\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"}
当我尝试使用如下参数调用 ASP.NET WebMethod 时:
var dataToSend = '{"recordID":"' + id + '"}';
var URLDataForm = 'FundsMain.aspx/Get';
oriEntity = GetDataFromWebMethod(URLDataForm, dataToSend);
有这样的功能
function GetDataFromWebMethod(webMethodUrl, dataToSend) {
if (webMethodUrl == '' || webMethodUrl === undefined) return null;
var data;
$.ajax({
type: 'POST',
data: dataToSend,
contentType: "application/json; charset=utf-8",
dataType: "json",
url: webMethodUrl,
async: false,
cache: false,
success: function (responseTxt) {
data = $.parseJSON(responseTxt.d.ResponseData);
},
error: function (err) {
showMessageBox("error", "Error", "GetDataFromWebMethod(): " + err.responseText);
}
});
return data;
}
网络方法:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static AjaxResponse Get(int recordID)
{
// remove for brevity
}
带有以下调试数据:
- in Firefox: dataToSend "{"recordID":"1625"}"
- in IE <10: dataToSend "{\"recordID\":\"1625\"}" String
- in Chrome: dataToSend:"{"recordID":"1625"}"
- in IE 10: dataToSend "{\"recordID\":\"1625\"}" String **(same as IE <10 !)**
有人对此有任何想法吗?或者我想我错过了什么?感谢您的时间!