Javascript 调用由js输入参数类型的webservice函数
我有这样的c#.net web服务Javascript 调用由js输入参数类型的webservice函数,javascript,c#,jquery,web-services,Javascript,C#,Jquery,Web Services,我有这样的c#.net web服务 [WebMethod] public string GetReportResult(int ReportID,params object[] Parameters) { return "hello"; } [WebMethod] public string Hello(string hello) { return hello; } 对于hello函数,我可以调用函数,但GetReportResult我不能 我的jquery ajax是这样的
[WebMethod]
public string GetReportResult(int ReportID,params object[] Parameters)
{
return "hello";
}
[WebMethod]
public string Hello(string hello)
{
return hello;
}
对于hello函数,我可以调用函数,但GetReportResult我不能
我的jquery ajax是这样的
var webMethod = "ws.asmx/Hello";
var parameters = "{'ReportID':10,}";
$.ajax({
type: "POST",
url: "ws.asmx/GetReportResult",
dataType: 'json',
contentType: 'application/json; charset=utf-8',
data: parameters,
success: function (msg) {
alert(msg.d);
},
error: function (jqXHR, textStatus, errorThrown) {
alert(errorThrown);
}
});
});
我想通过jquery调用这个web服务,但我不知道如何将数据发送到params value
大家都能帮我吗?我在jQuery中使用数组发送了输入。下面是代码的工作示例
$(document).ready(function() {
var cars = ["Saab", "Volvo", "BMW"];
var webMethod = "ws.asmx/Hello";
var parameters = "{'ReportID':10,'Parameters':['Name1','Name2']}";
$.ajax({
type: "POST",
url: "ws.asmx/GetReportResult",
dataType: 'json',
contentType: 'application/json; charset=utf-8',
data: parameters,
success: function(msg) {
alert(msg.d);
},
error: function(jqXHR, textStatus, errorThrown) {
alert(errorThrown);
}
});
});
只要发送一个数组,“params”在您从代码调用它时只启用params参数语法-它仍然是一个简单的数组。第一个问题是:为什么要用params声明WebMethod?@YeldarKurmangaliyev,你能解释一下吗?@mpf82谢谢你,我的朋友,我用这种方式解决了我的问题,等待系统让我检查我的答案