Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
178
rated 0 times [  185] [ 7]  / answers: 1 / hits: 131086  / 14 Years ago, mon, december 6, 2010, 12:00:00

How to access PHP session variables from jQuery function in a .js file?
In this code, I want to get value from a session variable



$(function() {
$(#progressbar).progressbar({
value: 37
});
});

More From » php

 Answers
52

You can produce the javascript file via PHP. Nothing says a javascript file must have a .js extention. For example in your HTML:



<script src='javascript.php'></script>


Then your script file:



<?php header(Content-type: application/javascript); ?>

$(function() {
$( #progressbar ).progressbar({
value: <?php echo $_SESSION['value'] ?>
});

// ... more javascript ...


If this particular method isn't an option, you could put an AJAX request in your javascript file, and have the data returned as JSON from the server side script.


[#94714] Friday, December 3, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
erinh

Total Points: 38
Total Questions: 100
Total Answers: 110

Location: Macau
Member since Mon, Nov 16, 2020
4 Years ago
;