//c# method
[WebMethod]
public static string HelloAction(string value)
{
Client clt = new Client();
clt.name = "Hello "+value;
return JsonConvert.SerializeObject(clt);
}
// Javascript code
var nameJson= {
"name" : "William"
};
$.ajax({
type: "POST",
data: JSON.stringify({ 'name': nameJson }), // ??
url: "Index.aspx/HelloAction",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: successHello
});
But chrome console show this error: POST http://localhost:9252/Index.aspx/HelloAction 500 (Internal Server Error)
{ name: nameJson }instead of{ 'name': nameJson }. Let me know if that works.nameJsonYou're double wrapping like this as it stands:{ 'name' : { 'name' : 'william' } }which will not work out properly. Unless that's a typo. Didn't see that at first.