【发布时间】:2015-06-01 06:24:49
【问题描述】:
我需要从我的网页调用 WCF 服务。服务中的方法使用泛型列表作为参数,我需要知道如何构建 ajax 查询?
方法:
public List<FileListEntity> ListLogFiles(string status, List<FileListEntity> fileList)
{
.............//implementation....
return fileList;
}
第一次调用方法时,'fileList' 作为 null 传递,此方法填充列表并将其发送回网站。网站第二次将接收到的 fileList 连同一些状态发送回服务。
ajax 查询:
var status = defineStatus();
var value;
var jsonObj;
function callLogService(){
debugger;
if (value == null) {
jsonObj = "null";
}
else {
jsonObj=value;
}
$.ajax({
type: "POST",
url: "http://localhost:56256/SearchService.svc/ListLogFiles",
data: '{"status":"'+ status+'","fileList":'+jsonObj+' }',
crossDomain: true,
contentType: "application/json; charset=utf-8",
dataType: "json",
processdata: true,
success: function (response) {
value = response;
display(value);
debugger;
alert("Success");
//debugger;
},
error: function () {
alert("An error has Occured, Please try refreshing !");
}
});
}
这在 jsonObj 为空时第一次有效,但在 jsonObj 包含值时第二次无效。 它说:
加载资源失败:服务器响应状态为 500(内部服务器错误)
我认为第二次没有正确传递参数。 任何想法?如何解决。
【问题讨论】:
标签: jquery ajax wcf rest restful-url