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 trial
Yusuf Bagha
28,853 PointsChanging a part of a Website Dynamically
How would I code a system that updates a page in real time. For example, if I posted a photo/status on a social network, how does that photo/status get updated on my friends wall?
I'm not creating a Social Network, but the same principals apply.
2 Answers
Rasmus Ishøi
Courses Plus Student 157 PointsOften you will want to make a lot of system script and such in PHP. PHP is running server-side meaning its kinda executed before it hits the browser, which is often referred to as being Synchronous. If you want to change the content on a site without reloading the site, you will want Asynchronous loading, which can be achieved by fx. AJAX. For using AJAX you will want to learn jQuery and/or Javascript (jQuery is a framework for Javascript).
Rasmus Ishøi
Courses Plus Student 157 PointsEDIT: Oops.
Yusuf Bagha
28,853 PointsSo then what would the JS programming look like, can you give me an example?
Rasmus Ishøi
Courses Plus Student 157 PointsOh, didn't realize that the tutorial for AJAX is not available yet. I'm actually terrible in JS, so you will want to take a look at this maybe: http://www.w3schools.com/php/php_ajax_php.asp or this: http://api.jquery.com/jquery.getjson/ for jQuery
Yusuf Bagha
28,853 PointsAlright Thank You Rasmus
Yusuf Bagha
28,853 PointsYusuf Bagha
28,853 PointsThanks for the answer, now I understand that but how would I write a PHP script that would do that, and how would that system work, and I already know JS and some PHP
Rasmus Ishøi
Courses Plus Student 157 PointsRasmus Ishøi
Courses Plus Student 157 PointsIt's not about writing the PHP to make it execute Asynchronously, it's about making the jQuery or JS script call the PHP script, and retrieve info to post in the browser. JS can work in the browser like it wants to, as the browser executes the JS script free of the server. Take a look at the AJAX basics: http://teamtreehouse.com/library/ajax-basics/upcoming
Yusuf Bagha
28,853 PointsYusuf Bagha
28,853 PointsSo simply have JS take the string data or file from the user, push it into the PHP script and have the PHP script throw it into the browser of the friends/ followers.
So JS is the one changing the html on the page not the PHP
Rasmus Ishøi
Courses Plus Student 157 PointsRasmus Ishøi
Courses Plus Student 157 PointsRoughly, yes.