【发布时间】:2017-07-11 15:55:44
【问题描述】:
我正在尝试进行 ajax 调用以通过 asmx webservice 提取 jqgrid 中的数据,但我收到了这个 Invalid web service call,缺少参数错误的值。
如果我删除 Web 服务调用和 ajax 请求中的输入参数,该函数运行良好,但一旦我有了输入参数,问题仍然存在。
以下是web服务方法
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public PersonsGrid Per(string PersonID)
{
....
return personsGrid;
}
以下是 Ajax 调用:
function getGridInfo() {
var personId = document.getElementById('txtPersonID').value;
$("#PersonsInfo").jqGrid({
url: '/Service/PersonsService.asmx/GetPersonsInfo',
data: "{'PersonID': '" + personId + "'}",
datatype: 'json',
mtype: 'POST',
async: false,
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
serializeGridData: function (postData) {
return JSON.stringify(postData);
},
jsonReader: { repeatitems: false, root: "d.rows", page: "d.page", total: "d.total", records: "d.records" },
loadonce: false,
colNames: ['ID', 'FirstName', 'LastName', 'Email', 'Phone'],
colModel: [
{ name: 'FirstName', index: 'FirstName', width: 100 },
{ name: 'LastName', index: 'LastName', width: 100 },
{ name: 'Email', index: 'Email', width: 100 },
{ name: 'Phone', index: 'Phone', width: 100 }
],
rowNum: 10,
rowList: [10, 20, 30],
viewrecords: true,
gridview: true,
rownumbers: true,
caption: 'Persons info',
loadError: function (xhr, textStatus, errorThrown) {
var error_msg = xhr.responseText;
var msg = "Some error occured during processing:";
msg += '\n\n' + error_msg;
alert(msg);
}
});
关于如何克服这个问题的任何想法。我关注了其他几个帖子,但仍然没有用。它必须对 ajax 请求中的 data 参数做一些事情。
【问题讨论】:
-
您的 mType 不应该是“GET”而不是“POST”吗?
-
即使这样,我也会得到同样的错误,我还在web方法中添加了usehttpget = true。
标签: javascript c# jquery ajax jqgrid