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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何使用制表工具通过ajax提供工具提示文本?相关的知识,希望对你有一定的参考价值。

我想通过请求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...
        }
    }

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

答案

经过一段时间试图找出发生了什么,我只是将我的调用同步并解析为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()); }

以上是关于如何使用制表工具通过ajax提供工具提示文本?的主要内容,如果未能解决你的问题,请参考以下文章

如何使CSS工具提示在原始项目上严格保持,而不是在新生成的工具提示上?

如何自动将工具提示文本内容包装到多行?

如何使用jquery提供的$ajax方法向后台传对象集合

jQuery UI 工具提示小部件中的 AJAX 内容

将部分数据工具提示文本设置为粗体

包含 ajax 后如何初始化引导工具提示?