kamel
kamel

Reputation: 45

Using Jquery AJAX to get object from ASP.NET web server

I'm trying to call an asp.net web service using Jquery Ajax post method like:

$.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 web method that looks like

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

The problem is I get an error in return saying "500 internal server error" and

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

I've tried this for data :

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

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

Does any body know how to handle this please?

Upvotes: 4

Views: 503

Answers (2)

kamel
kamel

Reputation: 45

Thank you Fabrizio that was part of the answer! I finally figured it out:

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

Works like a charm.

Upvotes: 0

Fabrizio Calderan
Fabrizio Calderan

Reputation: 123377

just try with

data : {Id :"thisistheid"}

without quotes around the object

Upvotes: 1

Related Questions