【发布时间】:2015-01-20 00:03:17
【问题描述】:
我的代码后面有一个中继器,它已经有一个列表,现在我在数据库表中添加了一个新行,其中包含中继器通过普通 Web 服务在 Web 窗体上显示的数据,这很好用.
假设我的 Web 服务方法向我的 ajaxSuccess 响应返回一个列表,我如何使用新列表更新我的转发器,或者我如何在 ajaxSuccess 方法中将新行添加到 UI。方法如下。
function UpdateUserServices(selectedService, userId) {
$.ajax({
type: "POST",
url: "PresentationService.asmx/UpdateUserServices",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify({'selectedService': selectedService,
'userId': userId
}),
success: function(response) {
//add new row to the asp.net repeater before closing dialog
$(".dvAddServices").dialog("close");
},
error: function(response) {
alert(response.d);
}
});
}
【问题讨论】:
-
当数据下来时,它是包含所有行还是只包含新行?如果是所有的行,新的行是这样标记的吗?
-
在客户端向表中添加一行并不难。主要问题是添加行后您打算做什么,因为当您回发到服务器时它不会持续存在。
-
@mason 这是最好的方法,我认为只返回行是理想的,你为什么问这个?它与添加到中继器的方式有关吗?
-
@Win 该行保存在数据库中,因此我需要它反映在 UI 中并保留在那里,除非我选择再次删除它。你有解决办法吗?
-
最好只返回新行,因为数据库中已经存在的行已经存在于客户端。你使用回传吗?如果不是,那么它应该非常简单,并且其中一个或两个答案都应该有效。如果你
标签: jquery asp.net ajax web-services repeater