我正在尝试将一些简单的参数发布到.asmx webservice.
我收到以下错误:请求格式无效:application/json; 字符集= UTF-8.
我真正需要的是能够传递一个复杂的对象,但我无法通过json内容类型发出POST请求.
这是我的WebService定义
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public int JsonTest2(int myparm1, int myparm2)
{
return 101;
}
Run Code Online (Sandbox Code Playgroud)
这是我的javascript代码
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);
}
});
}
Run Code Online (Sandbox Code Playgroud)