How to output JSON columns in jQuery

I am using the qTip jQuery plugin to create dynamic tooltips. The tooltip sends an id to cfc, which launches the request and returns the data in JSON format.

A tooltip is currently loading as follows:

{"COLUMNS:" ["BOOKNAME","BOOKDESCRIPTION"["MYBOOK","MYDESC"]]} 

Here jQuery

$('#catalog a[href]').each(function()
{
    var gi = parseInt($(this).attr("href").split("=")[1])
    $(this).qtip(
    {
        content: {
            url: 'cfcs/viewbooks.cfc?method=bookDetails',
            data: { bookID: gi  },
            method: 'get',
            title: {
                text: $(this).text(),
                button: 'Close'
            }
        },
        api :{
        onContentLoad : function(){
            }
        },
    });
});

As I mentioned, the data is returned successfully, but I'm not sure how to output and format it using HTML.

I tried to add content: '<p>' + data.BOOKNAME+ '

'in the api :{ onContentLoad : function(){ .....to see if I can get it to output something, but I get "data undefined error"

What is the correct way to try and output this data when formatting HTML?

+3
3

, ColdFusion, , ajax. "", ColdFusion . ajax.

0

qTip forums, , ajax api. , ?

:

$(this).qtip({
 content: 'Loading...',
 api: {
  onRender: function()
  {
   // Setup your AJAX request here
   $.ajax({
    url: DOC_ROOT + "admin/ajax/tooltip_process.php",
    type: 'GET';
    contentType: "application/json charset=utf-8",
    dataType: "json",
    success: function(json) {
     if(json[0].result == 'success') return json[0].tip;
     else alert('^$%#$#$');
    }
   });
  }
});
+2

dataType json . jquery, json, , . , , HTML .

0

Source: https://habr.com/ru/post/1747693/


All Articles