我尝试将包含两个整数的数组传递给 web 服务的函数:
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public bool sample(int number, int[] numbers)
{
return (numbers.Sum() > number);
}
我用 jquery.ajax 来做:
var arr = ['20', '89'];
$.ajax({ url: "Registration.asmx/sample",
data: jQuery.param({ 'number': '300', 'numbers[]': arr }),
type: "POST",
success: function (data) {
$('#result').html(data.toString());
},
error: function (xhr, ajaxOptions, thrownError) {
$('#result').html(jQuery.param({ 'number': '300', 'numbers': arr }) + "<br/><br/>" +
thrownError + "<br/><br/>" +
xhr.responseText);
}
});
但我总是收到关于空数组的服务器内部错误(我认为)