【发布时间】:2013-05-21 01:00:42
【问题描述】:
这是我第一次尝试使用 Ajax 向服务器发送数据。我从这里得到了很多答案,但我不会停止收到错误:"Message":"Invalid web service call, missing value for parameter: \u0027Products\u0027."
我关注了this 和this,但还是一样。谁能告诉我哪里出错了。
var products = [ { ProductId : 1, ProductName : "Mercedes", Category : "Cars", Price : 25000 }, { ProductId : 2, ProductName : "Otobi", Category : "Furniture", Price : 20000 } ];
function GetProductId() {
$.ajax({
type: "POST",
url: "Default.aspx/GenerateQrCode",
data: { "Products" : products.toString() },
contentType: "application/json; charset=utf-8",
dataType: "json",
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(xhr.responseText);
alert(thrownError);
},
success: function (msg) {
alert('Success');
}
});
}
[WebMethod]
public static void GenerateQrCode(object Products)
{
//Cannot get to here
}
【问题讨论】:
-
try :
data: { Products : products },jQuery 会为你解析对象- -
这不起作用。同样的错误。
标签: jquery ajax json webmethod