I have a PHP class/object which acts as the primary data source for my webpage. I'm using jQuery/Javascript to provide a dynamic interactive experience for the user. Both parts work independently really well.
I'm now trying to find an elegant and clean way for the javascript library I've written to access and update data stored in the PHP object.
Communication Javascript -> PHP: I've previously always created a PHP wrapper that takes input over the GET/POST and routes the data to the appropriate PHP function. This works well enough but surely there is a cleaner way to interface from javascript to PHP?
Communicating PHP -> Javascript: Previous websites I've written have seen communication from javascript to PHP only. The PHP would output HTML which Javascript would place in a container (Standard javascript usage I guess). However, in this website, the Javascript library I've written requires structured data in return which it processes to perform multiple UI updates. It seems that looking into JSON would be the right thing here but there seem to be a variety of options.
I would love the advice on the best way to get your PHP and Javascript communicating in both directions is a clean and elegant way.
Thanks!