Как кормить текст подсказки через ajax с помощью табулятора? - PullRequest
0 голосов
/ 03 января 2019

Я хочу заполнить свою дополнительную информацию всплывающей подсказкой, запросив вызов 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);
        }
    }); 
}

И теперь в этом проекте веб-формы я создал файл .asmx, который имеет определение веб-метода ...

    [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...
        }
    }

Я провел много исследований, но я не могу найти никакого решения ... Что я делаю не так? Это возможно?

1 Ответ

0 голосов
/ 03 января 2019

Через некоторое время, пытаясь выяснить, что произошло, я просто сделал свой вызов синхронным и проанализировал его в 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()); }
...