I'm trying to post some simple parameters to a .asmx webservice.
I get the following error: Request format is invalid: application/json; charset=utf-8.
What I really need to get to is to be able to pass a complex object, but I can't get past making a POST request with json content type.
Here is my WebService Definition
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public int JsonTest2(int myparm1, int myparm2)
{
return 101;
}
And this is my javascript code
function JsonTest2() {
$.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);
},
error: function (msg) {
alert('failure');
alert(msg);
}
});
}
Make sure your ASMX service class is decorated with the [ScriptService]
attribute.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With