[Solved] How to loop through JSON AJAX response?


If its a valid JSON you can use $.each()

$.each() or jQuery.each() is used for iterating over javascript objects and arrays. 

Example : In the example below intArray is a JavaScript array. So to
loop thru the elements in the array we are using $.each() function.
Notice this function has 2 parameters

  1. The JavaScript object or array that we want to iterate over
  2. The callback function that will execute on each iteration
$(document).ready(function () {            
  var  intArray = [100, 200, 300, 400, 500];            
  var  result =  '';           
  $.each(intArray,  function (index, element) {               
    result +=  'Index = '  + index +  ', Value="  + element +  "<br/>';  
    alert(element); // alert the values 
  });           
  $('#resultDiv').html(result); //insert the concatinated values inside a div 

         
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>

<head>             
  </head >
     <body>     
       <div  id = "resultDiv" >
       </div>
     </body>
</html>

solved How to loop through JSON AJAX response?