Mapping json

Mapping json

classic12classic12 Posts: 228Questions: 60Answers: 4

Hi guys,

I have the following test data coming back from an ajax call

 [{"animID":"1","title":"Marina Gate I \u2013 Facilities","url":"<iframe width=\"100%\" height=\"700\" frameborder=\"0\" id=\"landingmap\" src=\"https:\/\/my.matterport.com\/show\/?m=bkh2QEaDmuu&amp;play=1&amp;brand=0&amp;help=0&amp;mls=0&amp;qs=1\"><\/iframe>","status":"active"},{"animID":"2","title":"Two Bedroom Show Apartment (Type 2F)","url":"<iframe width=\"100%\" height=\"700\" frameborder=\"0\" id=\"landingmap\" src=\"https:\/\/my.matterport.com\/show\/?m=H26hek9kPst&amp;play=1&amp;brand=0&amp;help=0&amp;mls=0&amp;qs=1\"><\/iframe>","status":"active"}]

I am using the following code but I am not getting any data showing.

dataReturned =  [];
getIframes=function(){
  req = Ajax("http://www.xxx.com/getIframes.php", "GET", '',iframesReturned);  
}  

function iframesReturned() {
   dataReturned =[];
     if (req.status == 200) { //success
          alert('data back '+ req.responseText);
          //dataReturned = JSON.parse(req.responseText);
          dataReturned = req.responseText;
          //alert(dataReturned);
          //alert(dataReturned[0][0].title);
          $("#dtIframes").DataTable().destroy();
          $('#dtIframes').empty();
          data = dataReturned;

        tableIframes =  $('#dtIframes').DataTable( { 
        
              columns: [
                   
                      {
                          data: "title",
                          title : ' Title ',
                          width : '150px'
                      }
                        
              
              ]
        })
         }
         }
Button1.onclick=function(){
  // get the iframe data and show in datatable.
  getIframes();      
  }

cheers

Steve Warby

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951
    Answer ✓

    You haven't configured any options for Datatables to get the data. Looks like you will need data, for example:

            tableIframes =  $('#dtIframes').DataTable( {
                  data: data,
                  columns: [
    

    Kevin

  • classic12classic12 Posts: 228Questions: 60Answers: 4

    Whoops, some late nights

    Cheers

    Steve Warby

  • classic12classic12 Posts: 228Questions: 60Answers: 4

    I am now getting

    DataTables warning: table id=dtIframes - Requested unknown parameter 'title' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Can you use the debugger on your table please?

    Allan

  • classic12classic12 Posts: 228Questions: 60Answers: 4

    I got it working by using a different php method.

    Cheers

    Steve Warby

This discussion has been closed.