I’ve spent some more time working with the JavaScript side of the Web recently. I updated my PHP classes to serialize themselves to JSON. Then I added Web pages to return that data. This allows me to easily transfer that data to the client browser and convert ti to JavaScript. That seems to be working really well. That also gave me an opportunity to try out jQuery for retrieving the data using Ajax. jQuery is really overkill for what I use it for, as I only use it to make the Ajax calls, and it can do so much more. I found an add-in for jQuery that adds timer functionality. I had started working on creating a timer with multiple observers that could be triggered at different intervals. But this jQuery plug-in already does what I planned to build. So I’m giving it a go as well.
So now that I can get the data transferred in a format that’s easy to work with, and can transfer to according to a schedule based on the different types of data, I needed to display it. That’s where Knockout comes into the picture. Knockout allows me to define fields in an HTML document and bind them to the data that I retrieve using jQuery. As part of the data binding process I can define formatting for the data when it’s displayed. So now I have a clearly defined separation of the data and the rules for formatting the data. Although both jQuery and Knockout have way more functionality than I need or plan to use, I think I’m going to like working with them. I just need to make sure I don’t get carried away trying to find ways to use the other features. That is the danger of using products like these. I end up looking for a problem to fit the solution I already have.
I’ve done a fair bit of prototyping using these products in my development environment. First it took me a while to get used to the way Knockout and jQuery work. Once I got the basics working, I started looking at scheduling the Ajax calls from the client to the server. Finally, I experimented with ways to format the data for display on the Web pages. I feel like I have all of those items working, as well as a plan on how best to integrate this into my existing Web pages. I still have a lot of work to complete, as well as testing. The sad part is that the Web pages will probably look exactly the same after I finish the conversion. But I learned some new techniques, the design is better from a purist point of view, and the site will hopefully be easier to maintain..