JavaScript and JavaScript-based libraries can access and manipulate the Document-Object Model(DOM).
jQuery provides convenient access to the DOM.
Work through this jQuery tutorial: How jQuery Works. Generally, you can follow the tutorial as written, but make the following modifications.
Load the most appropriate version of jQuery. Options:
Don’t use the “slimmed” version; it doesn’t include AJAX, which you’ll need for the next exercise.
Be sure to understand:
ready
event.
Save this code in lab07_1.html
.
jQuery-UI provides a number client-side UI widgets.
Make a copy of your solution to the previous exercise, call the new
version lab07.html
, and modify it to implement something
similar in function to the example shown on the right. Notes:
If you haven’t already done so, move the CSS style and JS scripts into separate files.
Import the appropriate jQuery-UI libraries (both CSS and JS).
Replace the hyperlink from exercise 7.1 with a jQuery-UI button or something similar (e.g., the “Get Data” button shown to the right). See jQuery UI Demos for examples.
Add an event handler (e.g., a button-press handler) that creates a new DOM element that can be used to display a “no data yet...” message (shown to the right).
$("<em>", {html: "no data
yet..."}).appendTo("body");
Note that the message should be displayed when the user presses the button, not before. You’ll use this feature to display data in the next exercise.
Save this code in lab07.html
for use in the next exercise.
The AJAX technologies support more natural, interactive interfaces. We’ll use jQuery’s AJAX API. As a reference, you can use the “jQuery’s Ajax-Related Methods” section of this Ajax tutorial.
Modify your solution to the previous exercise to implement something similar to example shown on the right as follows.
Upgrade your server to respond to a new route,
/hello
, by returning a JSON-formatted text message.
Upgrade your client code to:
Make an AJAX call to your server when the user presses the button. Configure the AJAX call to:
Handle the return data. Configure the AJAX success/fail handlers to:
result.name
).
Save this code in lab07.html
, updating the CSS style and JS
script as needed.
We will grade your work according to the following criteria: