javascript - How to transfer session php data from PHP to JS -


i working php session , array data filtering js in laravel 4 view. currently, php ooks in javascript portion.

<?php $number_of_posts = 7; ?>;     <?php $_session['posts_start'] = isset($_session['posts_start']) ? $_session['posts_start'] : $number_of_posts; ?>;      var start = {{ session::get('posts_start', 7) }};     var initialposts = <?php echo fanfollow::follows_json(auth::user()->get()->id,0, $_session['posts_start']); ?>;     var desiredposts = <?php echo $number_of_posts; ?>; 

this works fine, move javascript external js file, opposed mixing php , js.

my question is, how take php above , make accessible js without using php directly in js.

an example using html hidden input in view so:

<input type="hidden" id="num_posts" name="num_posts" value="{{$number_of_posts}}"> 

and pulling using js:

var number_posts = $('#num_posts').val(); 

can similar done code have above? (the session , array data?)

just echo value template system

<script> var number_posts = {{$number_of_posts}}; </script> 

and javascript code use number_posts should after code above.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -