AJAX Post prototype parameters missing by chance

Ok, so I have a .NET application that uses the Prototype library to call AJAX for web methods on the page to get the data. This application has been running for quite some time, no problem. Recently, a new user started using the app and experienced some strange problems.

Basically, he can use the application perfectly for a while, and then he just starts throwing errors in AJAX. Here is the error:

System.InvalidOperationException - Unable to perform the requested action: Invalid web service call, missing value for parameter: 'fleet'. at System.Web.Script.Services.WebServiceMethodData.CallMethod(Object target, IDictionary'2 parameters) at System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary'2 parameters) AT SYSTEM.WEB.SCRIPT.SERVICES.RESTHANDLER.INVOKEMETHOD(HTTPCONTEXT CONTEXT, WEBSERVICEMETHODDATA METHODDATA, IDICTIONARY`2 RAWPARAMS) at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData) 

This is not just one call, which is a mess, but any case of ajax is randomnly, and it always seems to be the first parameter in a web method called โ€œmissingโ€. making me believe that the data in the messages is not returned in any way? (related ? : JQuery Ajax message options are sometimes not sent to IE ).

I could never recreate this problem, and no one else experienced it. This makes me think that this is something special in this user system that is causing the problem. Unfortunately, they are a pretty important user, so I need to try to solve this problem. IE8 user has a browser. Here is the code that makes an ajax call using the prototype:

 function gAjax(url, params, onSuccess, onError, onException, onComplete) { new Ajax.Request(url, { method:'post', //Post contentType:"application/json; charset=utf-8", //As JSON postBody:Object.toJSON(params), //Post Body is JSON string sanitizeJSON:true, //Sanitize the JSON onComplete:onComplete, //Set user on complete onSuccess:onSuccess, //Set user on success onFailure:onError, //Set user on error onException:onException //Set user on exception }); } 

onComplete, onSuccess, onError, onException are function callbacks. params is an object like the following:

{'fleet': 'fleetVal', 'bean': 1234}

Url is a method such as Bin.aspx / LoadBinInfo. This method is defined in the backend as follows:

  <System.Web.Services.WebMethod()> _ Public Shared Function LoadBinInfo(ByVal fleet As String, ByVal bin As Integer) As Dictionary(Of String, Object) '..... 'Returns a dictionary of info End Function 

If anyone has any ideas as to what is going on, I would really appreciate any input! I can not find any information in my studies to lead me to a possible reason. Again, it seems that this happens with only one user, so itโ€™s possible that his browser setting is at its end (any ideas, what settings?). But then again, itโ€™s even sporadic for him, but as soon as it starts to happen, it happens all the time, until he closes the browser and starts.

+4
source share
1 answer

I am answering here because it seems that I do not have enough reputation to comment and not respond. Itโ€™s not entirely clear what is missing in the request, but I would continue to check the web logs (or install some kind of log) to see what the system actually receives. According to your description of the problem, the request somehow skips the "fleet" parameter. But you do not send such a value highlighted in the request, you send all the data to the message body as a serialized JSON string. So the data transmitted by gAjax is incorrect / complete, or something strange is happening on your server. I obviously suspect this is the first, but in any case, you should try to log in and debug from both ends. To start, I would do something like this:

 function gAjax(url, params, onSuccess, onError, onException, onComplete) { params['debug']=Object.toJSON(params); new Ajax.Request(url, //.... 

This will add a JSON string to the request so you can check exactly what is being sent.

Hope this helps!

0
source

Source: https://habr.com/ru/post/1434911/


All Articles