I’m creating a little web app to play videos. Data about the videos will be stored in a MySQL database. One of the features of the app will be google-instant-style results as you type. I’m using AJAX on my search page to call on a php script which will query the sql database and return relevant videos. I would like the video results to be displayed youtube-style: so, a thumbnail of the video, a big clickable title, info in smaller font below the title, and maybe a drop-down menu of actions to do with that video.
My question is essentially this: what should I use to transform the video data into a displayable result (i.e. HTML code)? PHP or Javascript?
Should I:
A.) Use php to query the sql database, format the result as xml and return it as the AJAX response … then use javascript to turn the xml into the HTML that will display the snazzy youtube-style thing I described above.
OR
B.) Do everything in php (query database and create the HTML code), and have javascript just copy and paste the AJAX response into the webpage.
Any advice appreciated!
I prefer getting and packaging information into JSON then delivering that to a receiving AJAX Request and let the JavaScript generate the HTML. Use JSON rather than XML, JSON is easier to handle and transport. But to answer your question it is a lot easier to generate HTML Client Side rather than using PHP scripts to generate HTML, I learned that the hard way.