Tuesday, March 7, 2017

Display laravel variable using javascript

when i try dd($conv) the data are there, but I still can't display them inside the script. Anyone know whats the problem, I have tried many ways but they doesn't seem to work.

  <h4></h4>
    <?php $conv = json_encode($row->transcript_text); ?>
    <script type="text/javascript">
        function splitArray() {
            var myStr = <?php echo $conv; ?>;
            var strArray = myStr.split(/(?= \| \d)/);

            // Display array values on page
            for (var i = 0; i < strArray.length; i++) {
                $("body").addClass('col-lg-offset-1').append("<h4>" + strArray[i] + "</h4>");
            })
        }
        splitArray();
    </script>



via Muharrem Smakiqi

Advertisement