我正在尝试调用服务器端方法并使用 $.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;
}