Parsing Mysql Into Javascript Arrays Through Php And Jquery
Solution 1:
This solution you posted:
<script>var jsonarray = <?phpecho json_encode($array); ?>;
// now you can use jsonarray in your javascript</script>
Is actually a very good approach. Using AJAX is drastically slower (because of network latency).
Unless you really need AJAX for some reason, you should avoid using it. It will add a noticeable split second of load time to the page, often for no benefit at all.
Above all when structuring your page, you want to try and reduce the number of individual network requests between the browser and the server. The less requests the faster your page will be. This is especially true for javascript and ajax, because they are unpredictable and browsers find it very difficult to optimise any part of the page where it's being used.
We're talking about one quarter of a second compared to one millionth of a second, for exactly the same end result.
Solution 2:
Making an AJAX call with jQuery is easy enough. Take a look at the documentation: http://api.jquery.com/jQuery.get/
Solution 3:
You can also do this without AJAX
var jsonarray = eval(<?phpecho json_encode($array); ?>);
Post a Comment for "Parsing Mysql Into Javascript Arrays Through Php And Jquery"