【发布时间】:2017-10-11 09:30:27
【问题描述】:
我有这样的数据
[{"billno":"111","amount":"2233.00"},{"billno":"222","amount":"2500.00"},{"billno":"333","amount":"3000.00"}]
我想将此记录存储在我的数据库中,所以在此之前我试图将这些记录发送到服务器
这是我的 AJAX 代码:
$('#btnAddVendor').click(function () {
var values = [];
$('table#ContentPlaceHolder1_GridView1 input.checkBoxClass:checked').each(function () {
var $row = $(this).closest('tr').children('td');
values.push({ 'billno': $row.eq(1).text(), 'amount': $row.eq(5).text() });
});
//html_data = JSON.stringify(values);
alert(JSON.stringify(values)); // this alert will display above values
$.ajax({
type: 'POST',
url: 'GPCreateCheque.aspx/setCheqVendorSearchEntry',
data: JSON.stringify(values),
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (result) {
alert(result.d);
},
error: function (result) {
alert("Not save");
}
});
})
WebMethod 代码
public partial class WebForm5 : System.Web.UI.Page
{
[WebMethod]
public static string setCheqVendorSearchEntry(vendorEntry[] values)
{
//here I will write the code to store the records in database
return "Success"; //for testing I return this string
}
}
public class vendorEntry{
public string billno { get; set; }
public string amount { get; set; }
}
我不知道如何从 ajax 接收。谢谢
更新错误消息
http://localhost:55047/GPCreateCheque.aspx/setCheqVendorSearchEntry 500 (Internal Server Error)
【问题讨论】:
-
错误是什么? 404页面?
venderEntrys为空? -
@GGO
Status:500 Internal server error -
为什么要将 json 转换为字符串。将其作为 json 作为数据传递:值。
-
@UbiquitousDevelopers 如何在服务器端传递和接收,这种数组值为json?
-
错误:函数(结果){console.log(结果); } 检查您的浏览器控制台是否有确切的错误
标签: c# jquery asp.net json ajax