jquery - Convert Json encoded data to javascript array and access value by index -


i getting json response ajax this

  echo  json_encode($data); 

ajax code:

  $.ajax({         url:"paymentslip/check",          data:{val:val},         type: 'post',         success:function(ajaxresult)         {             $("#jgoli").html(ajaxresult);         }     }); 

result getting is:

     [{"paymentid":"2","paymentlabno":"mr-622-040618",paymenttestid":"1"}] 

now want access json array in javascript index

      ajaxresult[0] = 2; i.e paymentid=2       ajaxresult[1] = 2; i.e paymentlabno=mr-622-040618 

how achieve that?

note: have tried many examples on stackoverflow, know question must have answered earlier. still stuck. appreciated.

$(document).ready(function(){      var data =  [{"paymentid":"2","paymentlabno":"mr-622-040618","paymenttestid":"1"}];      //loop on object key=>value      $.each(data, function(key, value){      //and diplay in result div          $('#result').append('<p>'+data[key]['paymentid']+'</p>');          $('#result').append('<p>'+data[key]['paymentlabno']+'</p>');           $('#result').append('<p>'+data[key]['paymenttestid']+'</p>');      });  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>  <div id="result"></div>


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -