Search code examples
asp.netajaxjsoninternet-explorer-10webmethod

Ajax can not pass parameter to WebMethod in IE 10 ONLY - Missing value for parameter: \u0027recordID\u0027


I searched again and again but no hope. And I started to think that this is a IE 10 bug. Because the code below worked fine for Chrome, Firefox, IE 7 8 9, and so on.

I got this error

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

when I tried to call an ASP.NET WebMethod with a parameter like this:

var dataToSend = '{"recordID":"' + id + '"}';
var URLDataForm = 'FundsMain.aspx/Get';
oriEntity = GetDataFromWebMethod(URLDataForm, dataToSend);

with a function like this

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:

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static AjaxResponse Get(int recordID)
{
      // remove for brevity
}

with below debugging data:

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

Anyone have any idea about this? Or I guess I missed something? Thank for your time!


Solution

  • This issue seem to be an IE 10 bug. Thanks for help @Damith :)