如果用户点击带有类注释的显示注释按钮,弹出窗口就会打开。我想用项目的注释填充此弹出窗口(网格视图是弹出窗口的内容)。html:
<div class="pop-up-comments">
<div class="pop-up-wrap-comments">
<div class="edit-form">
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:BoundField DataField="CommentText" HeaderText="CommentText" />
<asp:BoundField DataField="Date" HeaderText="Date" />
</Columns>
</asp:GridView>
</div>
<div class="user-controls">
<button class="close-popup btn btn-danger">Close</button>
</div>
</div>
</div>js
$(document).on("click", ".comments", function () {
var clicked = $(this);
var id = clicked.attr("data-id");
alert(id);
$.ajax({
type: "POST",
url: "Admin.aspx/ShowComments",
data: id,
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) {
var returnedstring = data.d;
alert(returnedstring);
}
});
$('.pop-up-comments').addClass('show-popup');
});c#
[WebMethod]
public static string ShowComments(string id)
{
return id;
}此WebMethod上的断点从不触发。为什么?以及如何将数组注释发送到datagridview ??
发布于 2015-08-20 22:04:56
JSON AJAX Page方法接受并返回ASP.NET,因此您需要将通过JSON.stringify发送的数据转换为JSON,如下所示:
$(document).on("click", ".comments", function () {
var clicked = $(this);
var id = clicked.attr("data-id");
alert(id);
var dataToSend = {
id: id
};
$.ajax({
type: "POST",
url: "Admin.aspx/ShowComments",
data: JSON.stringify(dataToSend),
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) {
var returnedstring = data.d;
alert(returnedstring);
}
});
$('.pop-up-comments').addClass('show-popup');
});https://stackoverflow.com/questions/32119701
复制相似问题