Qtip数据未定义错误

本文关键字:错误 未定义 数据 Qtip | 更新日期: 2023-09-27 18:22:08

我使用的是Qtip工具提示,我的内容来自JSON。当我单击工具提示显示内容时,在检查chrome中的元素时,我会得到一个错误,即"数据未定义"。

这是我的javascript代码。

 $('#accordion_functions ul li a span:nth-child(2)').each(function () {    
  $(this).qtip({
        content: {
    text: function(event,api) {
        $.ajax({
            url: 'http://localhost:51783/Help/GetHelpText.ashx', 
            type: 'GET',
            dataType: 'json', 
           data: {
             id: $(this).attr('id') // Pass through the ID span
            },                  
        })
        .then(function(content) {
            var content = 'Help' + data.Text;                                
            api.set('content.text', content);
        }, function(xhr, status, error) {
            api.set('content.text', status + ': ' + error);
        });
        return 'Loading' // Set some initial loading text
    }
},
        hide: {
            event: 'click',
            fixed: true,
            delay: 50
        },
        show: {
            event: 'click',
            solo: true
        },
        events: {
            show: function (event, api) {
                $(api.elements.target).addClass('highlight');
            },
            hide: function (event, api) {
                $(api.elements.target).removeClass('highlight');
            }
        },
        style: {                
            width: 1200,
            padding: 5,
            tip: 'bottomRight',
        },
        position: {
            my: 'bottom right',
            at: 'bottom middle'
        }
    });

url发布的数据如下所示:

[{"id":"PCG01","Form":"Party Company","Tab":"General","Text":"Help needed here"},{"id":"PCG02","Form":"Party Company","Tab":"Contact","Text":"This is a second help"},{"id":"PCG03","Form":"Party Company","Tab":"Settlement","Text":"Third help"},{"id":"PCG04","Form":"Party Company","Tab":"Client","Text":"Fourth help"},{"id":"PCG05","Form":"Party Company","Tab":"Trade Constraints","Text":"Fifth help"},{"id":"PCG06","Form":"Party Company","Tab":"Attachments","Text":"Sixth help"}]

我可能做错了什么?

Qtip数据未定义错误

它不是在.then 中吗

    .then(function(content) {
        var **contentText** = 'Help' + **content**.Text;                                
        api.set('content.text', **contentText**);

问题出现在.then中。我访问json对象的方式基本上是错误的。

我将.then从:更改为

.then(function(content) {
        var content = 'Help' + data.Text;                                
        api.set('content.text', content);
    }, 

收件人:

.then(function(content) {                
            var content = 'Help' + content[0].Text +'';                                                
            api.set('content.text', content);
        },