如何使用制表工具通过ajax提供工具提示文本?

问题描述 投票:1回答:1

我想通过请求Ajax调用来填充我的额外信息工具提示。

这是我的JS表:

    var table = new Tabulator("#GridView1", {
        layout: "fitColumns",
        columns: [
            { title: "Autor PC", field: "Autor PC", width: 200, tooltip: function (cell) { return mouseover(cell.getValue()); } },
            //Other columns........
        ]
    });

这是我定义AJAX调用的函数。

function mouseover(user) {
    $.ajax({
        type: "GET",
        url: "AjaxServices.asmx/UsuarioInfo",
        data: JSON.stringify('{usuario: "' + user + '" }'), 
        contentType: "application/json; charset=UTF-8",
        dataType: "json",
        success: function (msg) {
            alert("correct: "+ msg.d);
        },
        error: function (msg) {
            alert("error: " + msg.d);
        }
    }); 
}

现在在这个webform项目中,我创建了一个.asmx文件,它具有webmethod的定义......

    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class AjaxServices : System.Web.Services.WebService
    {
        [WebMethod]
        public static string UsuarioInfo(string usuario)
        {
            //My logic that will return the user info...
        }
    }

我做了很多研究,但我找不到任何解决方案......我做错了什么?这可能吗?

javascript ajax asp.net-ajax tabulator
1个回答
0
投票

经过一段时间试图找出发生了什么,我只是将我的调用同步并解析为JSON ...

function mouseover(user) {

    return JSON.parse($.ajax({
        type: "POST",
        url: "AjaxServices.asmx/UsuarioInfo",
        async: false,
        data: '{ "usuario": "' + user + '"}', 
        contentType: "application/json; charset=UTF-8",
        dataType: "json",
        success: function (msg) {
            return msg.d;
        },
        error: function (msg) {
            //alert("erro " + msg.d);
        }
    }).responseText).d; 
}

然后我能够获得我的响应字符串并返回到工具提示中的函数。

tooltip: function (cell) { return mouseover(cell.getValue()); }
© www.soinside.com 2019 - 2024. All rights reserved.