首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用ajax调用在网格视图中显示注释

使用ajax调用在网格视图中显示注释
EN

Stack Overflow用户
提问于 2015-08-20 21:32:56
回答 1查看 323关注 0票数 0

如果用户点击带有类注释的显示注释按钮,弹出窗口就会打开。我想用项目的注释填充此弹出窗口(网格视图是弹出窗口的内容)。html:

代码语言:javascript
复制
<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

代码语言:javascript
复制
$(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#

代码语言:javascript
复制
 [WebMethod]
 public static string ShowComments(string id)
            {
                return id;
            }

此WebMethod上的断点从不触发。为什么?以及如何将数组注释发送到datagridview ??

EN

回答 1

Stack Overflow用户

发布于 2015-08-20 22:04:56

JSON AJAX Page方法接受并返回ASP.NET,因此您需要将通过JSON.stringify发送的数据转换为JSON,如下所示:

代码语言:javascript
复制
$(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');
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32119701

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档