This is the blog for getting Idea regarding PHP, Magento, jQuery and JavaScript for Customization.

Saturday 6 June 2015

PHP : Read PHP array using jQuery JSON

Hello Friends,


    I got this method after so many surfing, I hope this will help you for read PHP array to the jQuery.

    Using this can get the PHP array in JavaScript array!
PHP
   <?php

          $file = "Path of File Name";
          $csv = new Varien_File_Csv();
          $data = $csv->getData($file);

         Print_r($data); /*This will give Array of CSV file data*/

    ?>

   <script type="text/javascript">

          var sample = new Array();

          var vals = 'sample ';

          sample [vals] = '<?php echo json_encode($data) ?>';

         var sample_data = JSON.parse(sample ["sample"]);

   </script>

     Hope, this will useful to you !
, ,

No comments:

Post a Comment