How to show data of inner Array of JSON data using AJAX?












0















I have some sort of



[  
{
"selectionId":1,
"selectionDate":"101662",
"selectedBy":"ABC",
"eximPanNo":222,
"eximPanName":"DEF",
"eximPanNameEng":"KKK",
"eximPanAddress":null,
"eximPanAddressEng":null,
"eximPanPhone":12334566,
"selectionType":"G",
"consignmentNo":0,
"consignmentDate":"2098",
"productName":"LLL",
"selectionFromDate":"2019",
"selectionToDate":"2090",
"agentNo":123,
"selectionStatus":"I",
"entryBy":"PCS",
"entryDate":"2018-11-22 11:46:02",
"rStatus":"F",
"custOfficeId":1,
"selectionAudit":[
{
"audGrpId":1,
"selectionId":1,
"assignFromDate":"2075-08-03",
"assignToDate":"2075-08-19",
"entryBy":"1",
"rStatus":"1"
}
]
}
]


How can i show this selectionAudi.audGrpId data in dataTable when called from AJAX?
Here the Api is called through AJAX.



var table = $('#nepal').DataTable({
"processing" : true,
"ajax" : {
"url" : A_PAGE_CONTEXT_PATH + "/form/api/getAllSelectionAudit/all",
dataSrc : ''
},
"columns" : [ {
"data" : "selectionId"
}, {
"data" : "selectionDate"
}, {
"data" : "selectedBy"
}, {
"data" : "eximPanNo"
} ]
});


But when I add "data":"selectionAudi.audGrpId" then the datatable shows error like :
enter image description here



The code for table is:



<table id="nepal" class="table table-bodered">

<thead>
<tr>
<th>Selection No</th>
<th>SelectionDate</th>
<th>SelectedBy</th>
<th>PanEximNumber</th>
<th>AudiGroupID</th>


</tr>
</thead>
<tbody>

</tbody>

</table>


How can i show the inner Json data into datatable?I am not able to see what is the real solution.










share|improve this question























  • selectionAudit is an array with one object that has the audGrpId property, so you need selectionAudi[0].audGrpId to access the property.

    – cнŝdk
    Nov 23 '18 at 10:52













  • because it's an array, I would recommend you to use the custom render callback, using the data or row argument and checking whether selectionAudit exists in your object. Check this for reference: datatables.net/reference/option/columns.render

    – briosheje
    Nov 23 '18 at 10:57


















0















I have some sort of



[  
{
"selectionId":1,
"selectionDate":"101662",
"selectedBy":"ABC",
"eximPanNo":222,
"eximPanName":"DEF",
"eximPanNameEng":"KKK",
"eximPanAddress":null,
"eximPanAddressEng":null,
"eximPanPhone":12334566,
"selectionType":"G",
"consignmentNo":0,
"consignmentDate":"2098",
"productName":"LLL",
"selectionFromDate":"2019",
"selectionToDate":"2090",
"agentNo":123,
"selectionStatus":"I",
"entryBy":"PCS",
"entryDate":"2018-11-22 11:46:02",
"rStatus":"F",
"custOfficeId":1,
"selectionAudit":[
{
"audGrpId":1,
"selectionId":1,
"assignFromDate":"2075-08-03",
"assignToDate":"2075-08-19",
"entryBy":"1",
"rStatus":"1"
}
]
}
]


How can i show this selectionAudi.audGrpId data in dataTable when called from AJAX?
Here the Api is called through AJAX.



var table = $('#nepal').DataTable({
"processing" : true,
"ajax" : {
"url" : A_PAGE_CONTEXT_PATH + "/form/api/getAllSelectionAudit/all",
dataSrc : ''
},
"columns" : [ {
"data" : "selectionId"
}, {
"data" : "selectionDate"
}, {
"data" : "selectedBy"
}, {
"data" : "eximPanNo"
} ]
});


But when I add "data":"selectionAudi.audGrpId" then the datatable shows error like :
enter image description here



The code for table is:



<table id="nepal" class="table table-bodered">

<thead>
<tr>
<th>Selection No</th>
<th>SelectionDate</th>
<th>SelectedBy</th>
<th>PanEximNumber</th>
<th>AudiGroupID</th>


</tr>
</thead>
<tbody>

</tbody>

</table>


How can i show the inner Json data into datatable?I am not able to see what is the real solution.










share|improve this question























  • selectionAudit is an array with one object that has the audGrpId property, so you need selectionAudi[0].audGrpId to access the property.

    – cнŝdk
    Nov 23 '18 at 10:52













  • because it's an array, I would recommend you to use the custom render callback, using the data or row argument and checking whether selectionAudit exists in your object. Check this for reference: datatables.net/reference/option/columns.render

    – briosheje
    Nov 23 '18 at 10:57
















0












0








0








I have some sort of



[  
{
"selectionId":1,
"selectionDate":"101662",
"selectedBy":"ABC",
"eximPanNo":222,
"eximPanName":"DEF",
"eximPanNameEng":"KKK",
"eximPanAddress":null,
"eximPanAddressEng":null,
"eximPanPhone":12334566,
"selectionType":"G",
"consignmentNo":0,
"consignmentDate":"2098",
"productName":"LLL",
"selectionFromDate":"2019",
"selectionToDate":"2090",
"agentNo":123,
"selectionStatus":"I",
"entryBy":"PCS",
"entryDate":"2018-11-22 11:46:02",
"rStatus":"F",
"custOfficeId":1,
"selectionAudit":[
{
"audGrpId":1,
"selectionId":1,
"assignFromDate":"2075-08-03",
"assignToDate":"2075-08-19",
"entryBy":"1",
"rStatus":"1"
}
]
}
]


How can i show this selectionAudi.audGrpId data in dataTable when called from AJAX?
Here the Api is called through AJAX.



var table = $('#nepal').DataTable({
"processing" : true,
"ajax" : {
"url" : A_PAGE_CONTEXT_PATH + "/form/api/getAllSelectionAudit/all",
dataSrc : ''
},
"columns" : [ {
"data" : "selectionId"
}, {
"data" : "selectionDate"
}, {
"data" : "selectedBy"
}, {
"data" : "eximPanNo"
} ]
});


But when I add "data":"selectionAudi.audGrpId" then the datatable shows error like :
enter image description here



The code for table is:



<table id="nepal" class="table table-bodered">

<thead>
<tr>
<th>Selection No</th>
<th>SelectionDate</th>
<th>SelectedBy</th>
<th>PanEximNumber</th>
<th>AudiGroupID</th>


</tr>
</thead>
<tbody>

</tbody>

</table>


How can i show the inner Json data into datatable?I am not able to see what is the real solution.










share|improve this question














I have some sort of



[  
{
"selectionId":1,
"selectionDate":"101662",
"selectedBy":"ABC",
"eximPanNo":222,
"eximPanName":"DEF",
"eximPanNameEng":"KKK",
"eximPanAddress":null,
"eximPanAddressEng":null,
"eximPanPhone":12334566,
"selectionType":"G",
"consignmentNo":0,
"consignmentDate":"2098",
"productName":"LLL",
"selectionFromDate":"2019",
"selectionToDate":"2090",
"agentNo":123,
"selectionStatus":"I",
"entryBy":"PCS",
"entryDate":"2018-11-22 11:46:02",
"rStatus":"F",
"custOfficeId":1,
"selectionAudit":[
{
"audGrpId":1,
"selectionId":1,
"assignFromDate":"2075-08-03",
"assignToDate":"2075-08-19",
"entryBy":"1",
"rStatus":"1"
}
]
}
]


How can i show this selectionAudi.audGrpId data in dataTable when called from AJAX?
Here the Api is called through AJAX.



var table = $('#nepal').DataTable({
"processing" : true,
"ajax" : {
"url" : A_PAGE_CONTEXT_PATH + "/form/api/getAllSelectionAudit/all",
dataSrc : ''
},
"columns" : [ {
"data" : "selectionId"
}, {
"data" : "selectionDate"
}, {
"data" : "selectedBy"
}, {
"data" : "eximPanNo"
} ]
});


But when I add "data":"selectionAudi.audGrpId" then the datatable shows error like :
enter image description here



The code for table is:



<table id="nepal" class="table table-bodered">

<thead>
<tr>
<th>Selection No</th>
<th>SelectionDate</th>
<th>SelectedBy</th>
<th>PanEximNumber</th>
<th>AudiGroupID</th>


</tr>
</thead>
<tbody>

</tbody>

</table>


How can i show the inner Json data into datatable?I am not able to see what is the real solution.







javascript json ajax datatable






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 '18 at 10:40









ashwin karkiashwin karki

22711




22711













  • selectionAudit is an array with one object that has the audGrpId property, so you need selectionAudi[0].audGrpId to access the property.

    – cнŝdk
    Nov 23 '18 at 10:52













  • because it's an array, I would recommend you to use the custom render callback, using the data or row argument and checking whether selectionAudit exists in your object. Check this for reference: datatables.net/reference/option/columns.render

    – briosheje
    Nov 23 '18 at 10:57





















  • selectionAudit is an array with one object that has the audGrpId property, so you need selectionAudi[0].audGrpId to access the property.

    – cнŝdk
    Nov 23 '18 at 10:52













  • because it's an array, I would recommend you to use the custom render callback, using the data or row argument and checking whether selectionAudit exists in your object. Check this for reference: datatables.net/reference/option/columns.render

    – briosheje
    Nov 23 '18 at 10:57



















selectionAudit is an array with one object that has the audGrpId property, so you need selectionAudi[0].audGrpId to access the property.

– cнŝdk
Nov 23 '18 at 10:52







selectionAudit is an array with one object that has the audGrpId property, so you need selectionAudi[0].audGrpId to access the property.

– cнŝdk
Nov 23 '18 at 10:52















because it's an array, I would recommend you to use the custom render callback, using the data or row argument and checking whether selectionAudit exists in your object. Check this for reference: datatables.net/reference/option/columns.render

– briosheje
Nov 23 '18 at 10:57







because it's an array, I would recommend you to use the custom render callback, using the data or row argument and checking whether selectionAudit exists in your object. Check this for reference: datatables.net/reference/option/columns.render

– briosheje
Nov 23 '18 at 10:57














2 Answers
2






active

oldest

votes


















2














Your problem is that selectionAudit is an array with one object that contains the audGrpId property, so writing just selectionAudi.audGrpId is what's throwing this Error, because it's trying to access the audGrpId property in the array.



What you need is to write selectionAudit[0].audGrpId to access the right property.



This is how should be your code:



var table = $('#nepal').DataTable({
"processing" : true,
"ajax" : {
"url" : A_PAGE_CONTEXT_PATH + "/form/api/getAllSelectionAudit/all",
dataSrc : ''
},
"columns" : [ {
"data" : "selectionId"
}, {
"data" : "selectionDate"
}, {
"data" : "selectedBy"
}, {
"data" : "eximPanNo"
}, {
"data" : "selectionAudit[0].audGrpId"
]
});


Note:



This assumes selectionAudit is an array and it's always filled with this object.






share|improve this answer


























  • Just a side note: this will fail if selectionAudit is an empty array. Not sure this will ever happen, but still...

    – briosheje
    Nov 23 '18 at 11:02











  • @briosheje Yes, you are right, but I assumed it's always like this.

    – cнŝdk
    Nov 23 '18 at 11:03



















0














You can follow the way I usually do it not server side processing of datatable.



Suppose you HTML page from where you are making API calls -



<!-- Button to make API request -->
<button id="btnAPIRequest">API Request</button>

<!-- API response div -->
<div id="responseAPI"></div>


Call the API request through AJAX GET method and add below javascript code in bottom of your HTML page -



<script>
$("#btnAPIRequest").click(function(){
$.ajax({
type: "GET",
url: "Your/url/to/page.php",
data: 'if you have any data else blank',
dataType: 'json',
success: function(data){
if(data.success){
$("#responseAPI").html(data.message);

// Initialize datatable here
}
else{
$("#responseAPI").html(data.message);
}
}
});
});
</script>


Now in your php page where you actually calls the API and decode the json response -



<?php  
// Load the reuiqred library

// Make API request

// Get the resonse in json
$response = '[{"selectionId":1,..."selectionAudit":[{"audGrpId":1,..."rStatus":"1"}]}]';

// Decode the json response
$decoded_data = json_decode($response);

// Get your html table
$msg = '
<table>
<thead>
<tr>
<th>Selection No</th>
<th>SelectionDate</th>
<th>SelectedBy</th>
<th>PanEximNumber</th>
<th>AudiGroupID</th>
</tr>
</thead>
<tbody>
';

// Table body data
foreach($decoded_data as $data){
$msg .= '
<tr>
<td>'.$data[0].'</td>
<td>'.$data[2].'</td>
<td>'.$data[3].'</td>
<td>'.$data[4].'</td>
';

// I think here you got stuck when extracting from multidimensional array
foreach($data[n] as $audi_data){
$msg .= '<td>'.$audi_data[i].'</td>';
}

$msg .= '</tr>';
}

$msg .= '</tbody></table>';

// For success respone
// encode this value in json and ajax response will handle this as per return datatype option
echo json_encode(array('success'=>true, 'message'=>$msg));

// Similarly for failed response
echo json_encode(array('success'=>true, 'message'=>$msg));

?>





share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53445112%2fhow-to-show-data-of-inner-array-of-json-data-using-ajax%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    Your problem is that selectionAudit is an array with one object that contains the audGrpId property, so writing just selectionAudi.audGrpId is what's throwing this Error, because it's trying to access the audGrpId property in the array.



    What you need is to write selectionAudit[0].audGrpId to access the right property.



    This is how should be your code:



    var table = $('#nepal').DataTable({
    "processing" : true,
    "ajax" : {
    "url" : A_PAGE_CONTEXT_PATH + "/form/api/getAllSelectionAudit/all",
    dataSrc : ''
    },
    "columns" : [ {
    "data" : "selectionId"
    }, {
    "data" : "selectionDate"
    }, {
    "data" : "selectedBy"
    }, {
    "data" : "eximPanNo"
    }, {
    "data" : "selectionAudit[0].audGrpId"
    ]
    });


    Note:



    This assumes selectionAudit is an array and it's always filled with this object.






    share|improve this answer


























    • Just a side note: this will fail if selectionAudit is an empty array. Not sure this will ever happen, but still...

      – briosheje
      Nov 23 '18 at 11:02











    • @briosheje Yes, you are right, but I assumed it's always like this.

      – cнŝdk
      Nov 23 '18 at 11:03
















    2














    Your problem is that selectionAudit is an array with one object that contains the audGrpId property, so writing just selectionAudi.audGrpId is what's throwing this Error, because it's trying to access the audGrpId property in the array.



    What you need is to write selectionAudit[0].audGrpId to access the right property.



    This is how should be your code:



    var table = $('#nepal').DataTable({
    "processing" : true,
    "ajax" : {
    "url" : A_PAGE_CONTEXT_PATH + "/form/api/getAllSelectionAudit/all",
    dataSrc : ''
    },
    "columns" : [ {
    "data" : "selectionId"
    }, {
    "data" : "selectionDate"
    }, {
    "data" : "selectedBy"
    }, {
    "data" : "eximPanNo"
    }, {
    "data" : "selectionAudit[0].audGrpId"
    ]
    });


    Note:



    This assumes selectionAudit is an array and it's always filled with this object.






    share|improve this answer


























    • Just a side note: this will fail if selectionAudit is an empty array. Not sure this will ever happen, but still...

      – briosheje
      Nov 23 '18 at 11:02











    • @briosheje Yes, you are right, but I assumed it's always like this.

      – cнŝdk
      Nov 23 '18 at 11:03














    2












    2








    2







    Your problem is that selectionAudit is an array with one object that contains the audGrpId property, so writing just selectionAudi.audGrpId is what's throwing this Error, because it's trying to access the audGrpId property in the array.



    What you need is to write selectionAudit[0].audGrpId to access the right property.



    This is how should be your code:



    var table = $('#nepal').DataTable({
    "processing" : true,
    "ajax" : {
    "url" : A_PAGE_CONTEXT_PATH + "/form/api/getAllSelectionAudit/all",
    dataSrc : ''
    },
    "columns" : [ {
    "data" : "selectionId"
    }, {
    "data" : "selectionDate"
    }, {
    "data" : "selectedBy"
    }, {
    "data" : "eximPanNo"
    }, {
    "data" : "selectionAudit[0].audGrpId"
    ]
    });


    Note:



    This assumes selectionAudit is an array and it's always filled with this object.






    share|improve this answer















    Your problem is that selectionAudit is an array with one object that contains the audGrpId property, so writing just selectionAudi.audGrpId is what's throwing this Error, because it's trying to access the audGrpId property in the array.



    What you need is to write selectionAudit[0].audGrpId to access the right property.



    This is how should be your code:



    var table = $('#nepal').DataTable({
    "processing" : true,
    "ajax" : {
    "url" : A_PAGE_CONTEXT_PATH + "/form/api/getAllSelectionAudit/all",
    dataSrc : ''
    },
    "columns" : [ {
    "data" : "selectionId"
    }, {
    "data" : "selectionDate"
    }, {
    "data" : "selectedBy"
    }, {
    "data" : "eximPanNo"
    }, {
    "data" : "selectionAudit[0].audGrpId"
    ]
    });


    Note:



    This assumes selectionAudit is an array and it's always filled with this object.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 23 '18 at 13:16

























    answered Nov 23 '18 at 10:57









    cнŝdkcнŝdk

    23.7k63052




    23.7k63052













    • Just a side note: this will fail if selectionAudit is an empty array. Not sure this will ever happen, but still...

      – briosheje
      Nov 23 '18 at 11:02











    • @briosheje Yes, you are right, but I assumed it's always like this.

      – cнŝdk
      Nov 23 '18 at 11:03



















    • Just a side note: this will fail if selectionAudit is an empty array. Not sure this will ever happen, but still...

      – briosheje
      Nov 23 '18 at 11:02











    • @briosheje Yes, you are right, but I assumed it's always like this.

      – cнŝdk
      Nov 23 '18 at 11:03

















    Just a side note: this will fail if selectionAudit is an empty array. Not sure this will ever happen, but still...

    – briosheje
    Nov 23 '18 at 11:02





    Just a side note: this will fail if selectionAudit is an empty array. Not sure this will ever happen, but still...

    – briosheje
    Nov 23 '18 at 11:02













    @briosheje Yes, you are right, but I assumed it's always like this.

    – cнŝdk
    Nov 23 '18 at 11:03





    @briosheje Yes, you are right, but I assumed it's always like this.

    – cнŝdk
    Nov 23 '18 at 11:03













    0














    You can follow the way I usually do it not server side processing of datatable.



    Suppose you HTML page from where you are making API calls -



    <!-- Button to make API request -->
    <button id="btnAPIRequest">API Request</button>

    <!-- API response div -->
    <div id="responseAPI"></div>


    Call the API request through AJAX GET method and add below javascript code in bottom of your HTML page -



    <script>
    $("#btnAPIRequest").click(function(){
    $.ajax({
    type: "GET",
    url: "Your/url/to/page.php",
    data: 'if you have any data else blank',
    dataType: 'json',
    success: function(data){
    if(data.success){
    $("#responseAPI").html(data.message);

    // Initialize datatable here
    }
    else{
    $("#responseAPI").html(data.message);
    }
    }
    });
    });
    </script>


    Now in your php page where you actually calls the API and decode the json response -



    <?php  
    // Load the reuiqred library

    // Make API request

    // Get the resonse in json
    $response = '[{"selectionId":1,..."selectionAudit":[{"audGrpId":1,..."rStatus":"1"}]}]';

    // Decode the json response
    $decoded_data = json_decode($response);

    // Get your html table
    $msg = '
    <table>
    <thead>
    <tr>
    <th>Selection No</th>
    <th>SelectionDate</th>
    <th>SelectedBy</th>
    <th>PanEximNumber</th>
    <th>AudiGroupID</th>
    </tr>
    </thead>
    <tbody>
    ';

    // Table body data
    foreach($decoded_data as $data){
    $msg .= '
    <tr>
    <td>'.$data[0].'</td>
    <td>'.$data[2].'</td>
    <td>'.$data[3].'</td>
    <td>'.$data[4].'</td>
    ';

    // I think here you got stuck when extracting from multidimensional array
    foreach($data[n] as $audi_data){
    $msg .= '<td>'.$audi_data[i].'</td>';
    }

    $msg .= '</tr>';
    }

    $msg .= '</tbody></table>';

    // For success respone
    // encode this value in json and ajax response will handle this as per return datatype option
    echo json_encode(array('success'=>true, 'message'=>$msg));

    // Similarly for failed response
    echo json_encode(array('success'=>true, 'message'=>$msg));

    ?>





    share|improve this answer






























      0














      You can follow the way I usually do it not server side processing of datatable.



      Suppose you HTML page from where you are making API calls -



      <!-- Button to make API request -->
      <button id="btnAPIRequest">API Request</button>

      <!-- API response div -->
      <div id="responseAPI"></div>


      Call the API request through AJAX GET method and add below javascript code in bottom of your HTML page -



      <script>
      $("#btnAPIRequest").click(function(){
      $.ajax({
      type: "GET",
      url: "Your/url/to/page.php",
      data: 'if you have any data else blank',
      dataType: 'json',
      success: function(data){
      if(data.success){
      $("#responseAPI").html(data.message);

      // Initialize datatable here
      }
      else{
      $("#responseAPI").html(data.message);
      }
      }
      });
      });
      </script>


      Now in your php page where you actually calls the API and decode the json response -



      <?php  
      // Load the reuiqred library

      // Make API request

      // Get the resonse in json
      $response = '[{"selectionId":1,..."selectionAudit":[{"audGrpId":1,..."rStatus":"1"}]}]';

      // Decode the json response
      $decoded_data = json_decode($response);

      // Get your html table
      $msg = '
      <table>
      <thead>
      <tr>
      <th>Selection No</th>
      <th>SelectionDate</th>
      <th>SelectedBy</th>
      <th>PanEximNumber</th>
      <th>AudiGroupID</th>
      </tr>
      </thead>
      <tbody>
      ';

      // Table body data
      foreach($decoded_data as $data){
      $msg .= '
      <tr>
      <td>'.$data[0].'</td>
      <td>'.$data[2].'</td>
      <td>'.$data[3].'</td>
      <td>'.$data[4].'</td>
      ';

      // I think here you got stuck when extracting from multidimensional array
      foreach($data[n] as $audi_data){
      $msg .= '<td>'.$audi_data[i].'</td>';
      }

      $msg .= '</tr>';
      }

      $msg .= '</tbody></table>';

      // For success respone
      // encode this value in json and ajax response will handle this as per return datatype option
      echo json_encode(array('success'=>true, 'message'=>$msg));

      // Similarly for failed response
      echo json_encode(array('success'=>true, 'message'=>$msg));

      ?>





      share|improve this answer




























        0












        0








        0







        You can follow the way I usually do it not server side processing of datatable.



        Suppose you HTML page from where you are making API calls -



        <!-- Button to make API request -->
        <button id="btnAPIRequest">API Request</button>

        <!-- API response div -->
        <div id="responseAPI"></div>


        Call the API request through AJAX GET method and add below javascript code in bottom of your HTML page -



        <script>
        $("#btnAPIRequest").click(function(){
        $.ajax({
        type: "GET",
        url: "Your/url/to/page.php",
        data: 'if you have any data else blank',
        dataType: 'json',
        success: function(data){
        if(data.success){
        $("#responseAPI").html(data.message);

        // Initialize datatable here
        }
        else{
        $("#responseAPI").html(data.message);
        }
        }
        });
        });
        </script>


        Now in your php page where you actually calls the API and decode the json response -



        <?php  
        // Load the reuiqred library

        // Make API request

        // Get the resonse in json
        $response = '[{"selectionId":1,..."selectionAudit":[{"audGrpId":1,..."rStatus":"1"}]}]';

        // Decode the json response
        $decoded_data = json_decode($response);

        // Get your html table
        $msg = '
        <table>
        <thead>
        <tr>
        <th>Selection No</th>
        <th>SelectionDate</th>
        <th>SelectedBy</th>
        <th>PanEximNumber</th>
        <th>AudiGroupID</th>
        </tr>
        </thead>
        <tbody>
        ';

        // Table body data
        foreach($decoded_data as $data){
        $msg .= '
        <tr>
        <td>'.$data[0].'</td>
        <td>'.$data[2].'</td>
        <td>'.$data[3].'</td>
        <td>'.$data[4].'</td>
        ';

        // I think here you got stuck when extracting from multidimensional array
        foreach($data[n] as $audi_data){
        $msg .= '<td>'.$audi_data[i].'</td>';
        }

        $msg .= '</tr>';
        }

        $msg .= '</tbody></table>';

        // For success respone
        // encode this value in json and ajax response will handle this as per return datatype option
        echo json_encode(array('success'=>true, 'message'=>$msg));

        // Similarly for failed response
        echo json_encode(array('success'=>true, 'message'=>$msg));

        ?>





        share|improve this answer















        You can follow the way I usually do it not server side processing of datatable.



        Suppose you HTML page from where you are making API calls -



        <!-- Button to make API request -->
        <button id="btnAPIRequest">API Request</button>

        <!-- API response div -->
        <div id="responseAPI"></div>


        Call the API request through AJAX GET method and add below javascript code in bottom of your HTML page -



        <script>
        $("#btnAPIRequest").click(function(){
        $.ajax({
        type: "GET",
        url: "Your/url/to/page.php",
        data: 'if you have any data else blank',
        dataType: 'json',
        success: function(data){
        if(data.success){
        $("#responseAPI").html(data.message);

        // Initialize datatable here
        }
        else{
        $("#responseAPI").html(data.message);
        }
        }
        });
        });
        </script>


        Now in your php page where you actually calls the API and decode the json response -



        <?php  
        // Load the reuiqred library

        // Make API request

        // Get the resonse in json
        $response = '[{"selectionId":1,..."selectionAudit":[{"audGrpId":1,..."rStatus":"1"}]}]';

        // Decode the json response
        $decoded_data = json_decode($response);

        // Get your html table
        $msg = '
        <table>
        <thead>
        <tr>
        <th>Selection No</th>
        <th>SelectionDate</th>
        <th>SelectedBy</th>
        <th>PanEximNumber</th>
        <th>AudiGroupID</th>
        </tr>
        </thead>
        <tbody>
        ';

        // Table body data
        foreach($decoded_data as $data){
        $msg .= '
        <tr>
        <td>'.$data[0].'</td>
        <td>'.$data[2].'</td>
        <td>'.$data[3].'</td>
        <td>'.$data[4].'</td>
        ';

        // I think here you got stuck when extracting from multidimensional array
        foreach($data[n] as $audi_data){
        $msg .= '<td>'.$audi_data[i].'</td>';
        }

        $msg .= '</tr>';
        }

        $msg .= '</tbody></table>';

        // For success respone
        // encode this value in json and ajax response will handle this as per return datatype option
        echo json_encode(array('success'=>true, 'message'=>$msg));

        // Similarly for failed response
        echo json_encode(array('success'=>true, 'message'=>$msg));

        ?>






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 23 '18 at 11:27

























        answered Nov 23 '18 at 11:10









        Muhammad TariqueMuhammad Tarique

        447612




        447612






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53445112%2fhow-to-show-data-of-inner-array-of-json-data-using-ajax%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Create new schema in PostgreSQL using DBeaver

            Deepest pit of an array with Javascript: test on Codility

            Costa Masnaga