I’ve a ASP.NET WebAPI control below :
public SomeObject GetBenchMarkData(Comment comment)
{
//do stuff
}
On Client side I’m trying this below:
var comment = { ID: 0, Text: $('#text').val(), Author: $('#author').val(), Email: $('#email').val(), GravatarUrl: '' };
var json = JSON.stringify(comment);
$.getJSON("api/MintEIQAPI/" + json,
The problem is the GetBenchMarkData action never gets called with above getJSON query.
Could someone please help me, what I’m doing wrong?
Thanks.
The problem is that
getJSONexecutes aGETrequest to the server. For passing in entire objects, you have to execute aPOSTrequest.In the case of a GET, the JavaScript object you pass to the jQuery Ajax calls will normally be transformed into URL encoded parameters which could then be taken individually by your server-side method like
});
and on your server-side
Instead, if you want to transmit a whole object, you should execute the ajax call as a POST, like
And your server-side method must take an object with a property
Titleof typeString.My blog post might be of help here too.