Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialalexvalladares
21,478 PointsThis can be made also via jQuery or JavaScript
The question is: when do we use php, javascript or jquery for these kind of (simple) operations?
2 Answers
John Breslin
16,963 PointsPHP is server side, so it will return the same thing at the same speed regardless of what computer you're on. The user can't see the code typically, so it's better for manipulating sensitive data. You would use PHP for things that happen on page load, since it can't really do much once it's served you the html.
Javascript runs on the users computer, making it reliant on their hardware and installed version. Anybody can see what you've written in Javascript with little effort. But, it is necessary for things you want to happen after the page is already loaded, such as AJAX requests to the server and animations.
For simple operations, use javascript to minimize operations on your server or php for reliability. Or just use whatever you happen to be writing in when the operation comes up.
alexvalladares
21,478 PointsGreat answer, John. Really appreciate it!
John Breslin
16,963 PointsNo problem :)