You should use a value formatted as valid JSON data as data:
{"myparm1":105,"myparm2":23}
instead
{myparm1:105,myparm2:23}
You can check on the website http://www.jsonlint.com/ whose data is JSON data. Therefore you must change your code to
$.ajax({ type: 'POST', url: "http://localhost/WebServices/MyTest.asmx/JsonTest2", data: '{"myparm1":105,"myparm2":23}', contentType: 'application/json; charset=UTF-8', dataType: 'json', async: false, success: function (msg) { alert(msg.d); }, error: function (msg) { alert('failure'); alert(msg); } });
For more complex input parameters, I recommend using the JSON.stringify function from json2.js (see this answer ):
var myValue1 = 105, myValue2 = 23; $.ajax({ type: 'POST', data: JSON.stringify({myparm1:myValue1, myparm2:myValue2}), ... });
In the latest version of $.ajax using myValue1 and myValue2 can be complex structures (objects with properties) or arrays that even have other complex structures or arrays as properties.
Oleg
source share