Shared Json Data For Php And Javascript/ajax
I am writing a validation mechanizm for my website. Some code is used with Javascript and ajax to validate (mostly lengths of) strings. And some other code is used in php on the se
Solution 1:
You could create a Javascript file instead of a JSON one - just define all your variables in a PHP array, then make a PHP file with contents like:
var config = <?phpecho json_encode($config); ?>;
and load it like:
<scripttype="text/javascript"src="../includes/vars.php"></script>
(vars.js
would be a better name, but would require that your server knew to process *.js files as PHP.)
This will load your variables synchronously, and gets them into the global scope more easily than an asynchronous JSON load.
Post a Comment for "Shared Json Data For Php And Javascript/ajax"