asp.net - IE 10中只有缺少参数值,Ajax无法将参数传递给 web method: u0027recordIDu0027

  显示原文与译文双语对照的内容
0 0

我一次又一次地搜索,但没有希望。 我开始认为这是 IE 10 Bug 。 因为下面的代码适用于 Chrome,Firefox,IE 7 8 9,等等。

我收到这个错误

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

尝试使用这样的参数调用 ASP.NET web method时:

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;
}

web method:

[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!)**

对这个有任何了解? 或者我想我漏掉了一些? 感谢你的时间 !

时间:原作者:3个回答

...