How to format Ajax success->response before display

Hello,

After a successful response back through a AJAX call, how do I send the results back to the calling script(PHP) so that it can be formatted for display or do i need to pre-format before sending it back to the script?

 $.ajax({ type: "POST",                   
           url: 'phpFile.php', 
         data: $('#testForm').serialize(),
   success: function(response){
   **console.log("Stage 1 resp:: "+ response);**                        
      if(response == 'success') {

display.php - where the results will be displayed:
<div id="displayResults">Like it to be a table format<?div>

Results returned from above AJAX script

[{"ver_index":1,"var_projectID":"19032211553","var_version":"0.0.1","var_startDate":"2019-03-25 15:53:05"},
{"ver_index":2,"var_projectID":"19032211553","var_version":"0.0.2","var_startDate":"2019-03-25 15:53:05"},
{"ver_index":3,"var_projectID":"19032211553","var_version":"0.0.3","var_startDate":"2019-03-25 15:53:36"},
{"ver_index":4,"var_projectID":"19032211553","var_version":"0.0.4","var_startDate":"2019-03-25 15:53:36"}]

You could pre-format it while you are creating the results in your PHP code, or you could use javascript to split the data down and insert it into the page in the correct format. I’m not sure which is best - some might say that the client-side should be in charge of how the data is displayed, so you’d be best off handling it in your success function.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.