Return an array with AJAX
Hi, I'm new to AJAX
I have un page where i want to call an ajax request to add something on this page.
export.php
Here is my ajax function
requestColumns. php
I didn't get the way I can return an array from my requestColumns. php file to my jquery Ajax request and after use it to modify the DOM of my page export.php.
Thanks for your help.
Hi, I'm new to AJAX
I have un page where i want to call an ajax request to add something on this page.
export.php
Code:
<div class="row"> <div class="span12"> <select id="listTable" name="listTable"> <option value="appel">Appels</option> <option value="dossier">Dossiers</option> <option value="commande">Commandes Fournisseur</option> </select> </div> </div> <div class="row"> <div class="span12"> <button class="btn btn-primary" onClick="selectTable()">Select</button> </div> </div> <div id ="columns" class="row" style="display:none;"> <div class="span12"> <div id="columns-check" style=""> <!-- Here will be displayed the content of the ajax request--> </div> </div> </div> <script type="text/javascript" src="_module/ExportFichier/exportFile/ajax/requestExport.js"></script>
Code:
function selectTable(table){ var table = $("#listTable").val(); $.ajax({ url: "_module/ExportFichier/exportFile/ajax/requestColumns.php", type: "POST", data: "table="+table, dataType: 'json', success: function(data){ $('#columns').css('display','block'); $('#columns-check').empty(); for(i=0; i<data; i++){ $('#columns-check').prepend('<div>I would like to display here the content of my array</div>'); } }, error: function(){ alert('The Ajax request did not works!'); } }); }
Code:
header("content-type: application/json; charset=utf-8"); require_once '../requirements.php'; $tableName = $_POST["table"]; $objService = new ExportFileService($tableName); $columns = $objService->get_columns(); echo json_encode($columns);
I didn't get the way I can return an array from my requestColumns. php file to my jquery Ajax request and after use it to modify the DOM of my page export.php.
Thanks for your help.
Comment