Qtip数据未定义错误

时间:2013-07-12 10:39:08

标签: c# javascript asp.net json qtip2

我正在使用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'
        }
    });

网址发布的数据如下所示:

[{"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"}]

我可能做错了什么?

2 个答案:

答案 0 :(得分:2)

不在.then

    .then(function(content) {

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

答案 1 :(得分:0)

问题发生在.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);
        },