使用Ajax将JSON发送到ASP.NET Web方法

这是我第一次尝试使用Ajax将数据发送到服务器。 我从这里"Message":"Invalid web service call, missing value for parameter: \u0027Products\u0027."很多答案,但我不会停止收到错误: "Message":"Invalid web service call, missing value for parameter: \u0027Products\u0027."

我跟着这个 ,但仍然是一样的。 有人可以告诉我哪里出错了。

  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 } 

试试这个 –

 data : "{'Products':" + JSON.stringify(products) + "}" 

试试这个 –

 data : {Products: JSON.stringify(products)} 

要么

 data : {Products: products}