Using jQuery AJAX to get an object from an ASP.NET web server

I am trying to call an asp.net web service using the jquery Ajax mail method, for example:

$.ajax({ type: "POST", url: this._baseURL + method, data: data, contentType: "application/json; charset=utf-8", dataType: "json", success: fnSuccess, error: fnError }); 

On the server side, I have a web method that looks like

 public myClass myWebMethod(Guid Id) { ... } 

The problem is that I get the error "500 internal server errors" and

Invalid web service call, missing parameter value: \ u0027Id \ u0027.

I tried this for data:

'{"Id":"thisistheid"}' and '{ Id:thisistheid}'

... and many other combinations that I found in the examples.

Does anyone know how to handle this?

+4
source share
2 answers

just try

 data : {Id :"thisistheid"} 

without quotes around the object

+1
source

Thanks, Fabrizio, who was part of the answer! I finally figured this out:

 data = {Id :"thisistheid"}; ... $.ajax({ ... data: JSON.stringify(data), ... }); 

It works like a charm.

0
source

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


All Articles