0

私はQtipツールチップを使用しており、私のコンテンツは JSON からのものです。ツールチップをクリックしてコンテンツを表示すると、クロムで要素を検査するときに「データが定義されていません」というエラーが表示されます。

これは私の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"}]

私は何が間違っているのでしょうか?

4

2 に答える 2

2

の中にありませんか.then

    .then(function(content) {

        var **contentText** = 'Help' + **content**.Text;                                
        api.set('content.text', **contentText**);
于 2013-07-12T11:27:36.460 に答える
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);
        },
于 2013-07-12T14:48:01.403 に答える