Web Frameworks - Workbook - Week 08
Main Page >> Web Frameworks >> Workbook >> Workshop - week 08
Ajax: Increased responsiveness and interactivity of web pages is achieved by exchanging small amounts of data with the server "behind the scenes" so that the entire web page does not have to be reloaded each time there is a need to fetch data from the server. (Wikipedia.org)
As explained in class, it works like this:
- The user interacts with the page and triggers an event.
- JavaScript code sends a request to the server, and handles the response.
- Some server-side code handles the request (get data from database and return to client)
Let's get started!
Step 2
Yes, we'll start with step 2. We don't really want to type a load of JavaScript, since there are plenty of existing libraries available on the net (and this module is all about reusing code, right?).
You may have heard of jquery or the Prototype library. For this example we'll use the latter.
"Prototype is a JavaScript Framework that aims to ease development of dynamic web applications. Featuring a unique, easy-to-use toolkit for class-driven development and the nicest Ajax library around, Prototype is quickly becoming the codebase of choice for web application developers everywhere." (source)
Download the file from here, and save it to public/scripts as prototype.js.
Then add a link to it in your layout, by adding the following line in your <HEAD> section:
echo $this->headScript()->prependFile($this->baseUrl('/scripts/prototype.js'));