我正在尝试使用$ .ajax()调用服务器端方法并使用Json格式传递值,但是我收到了此错误:
{"Message":"Invalid web service call, missing value for parameter: \u0027obj\u0027.","StackTrace":" at System.Web.Script.Services.WebServiceMethodData.CallMethod(Object target, IDictionary`2 parameters)\r\n at System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary`2 parameters)\r\n at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"}
当我硬编码价值观时尝试发送,然后那是正确的..但无法传递Json对象。
客户端代码
<script type="text/javascript">
function DailyReportFn() {
debugger;
var RadTabStrip1 = $find("<%= RadTabStrip1.ClientID %>");
var tab = RadTabStrip1.findTabByText("Qualified Families");
var RadPageView1 = tab.get_pageView()
var elment = RadPageView1.get_element();
var DailyReport = {
NewReg: $find("<%= NewReg.ClientID %>").get_textBoxValue(),
Removed: $find('<%= Removed.ClientID %>').get_textBoxValue(),
Homevt: $find('<%= Homev.ClientID %>').get_textBoxValue()
}
$.ajax({
type: "POST",
url: '<%=ResolveUrl("~/DModules/Hc/WebMethods.aspx/DemoReport")%>',
data: JSON.stringify(DailyReport),
contentType: "application/json",
dataType: "json",
async: false,
cache: false,
success: function (data) {
debugger;
alert(data);
},
error: function (x, e) {
alert(x.responseText);
},
});
}
服务器端代码
[WebMethod, ScriptMethod]
public static int DemoReport(Drep report)
{
int result = -1;
int NewReg = report.NewReg;
int Removed = report.Removed;
int Homev = report.Homevt;
return result;
}
答案 0 :(得分:0)
在发布帖子之前,请先尝试检查JSON.stringify(DailyReport)的值。
var DailyReport = {
NewReg: $find("<%= NewReg.ClientID %>").get_textBoxValue(),
Removed: $find('<%= Removed.ClientID %>').get_textBoxValue(),
Homevt: $find('<%= Homev.ClientID %>').get_textBoxValue()
}
console.info(JSON.stringify(DailyReport));//OR: alert(JSON.stringify(DailyReport));
$.ajax({...
答案 1 :(得分:0)
试试这个
data: JSON.stringify({report:DailyReport}),