University of Washington CSE 154

Section 10: JSON; Web Services

Except where otherwise noted, the contents of this document are Copyright © Marty Stepp, Jessica Miller, and Victoria Kirst. All rights reserved. Any redistribution, reproduction, transmission, or storage of part or all of the contents in any form is prohibited without the author's expressed written permission.

Valid HTML5 Valid CSS

IMPORTANT NOTES:

Exercise : Address Book, Client-Side (by Alex Miller)

screenshot

Write the JS code to connect to a server-side JSON address book called addressbook.php. Start from this HTML. (sample solution) (solution)

Recall: Creating an Ajax POST request

var params = new FormData();
params.append("name", value);
params.append("name", value);

var ajax = new XMLHttpRequest();
ajax.onload = functionName;
ajax.open("POST", "url", true);
ajax.send(params);

Exercise : Address Book, Server-Side (by Alex Miller)

screenshot

Write the PHP code to manage an address book using JSON. You are given the HTML and JS. The JS code sends requests to your addressbook.php web service that reads and saves address data. (sample solution) (solution) Write the PHP file, addressbook.php, that provides the following behavior:

You may assume that any necessary parameters are passed and are in valid formats.

Exercise : Prime Factors XML (by Eli White)

Write a PHP web service factors-xml.php that computes and outputs prime factorization of integers as XML. (sample solution) (solution code) Provide the following behavior:

Exercise : Prime Factors JSON (by Eli White)

Write a PHP web service factors-json.php that computes and outputs prime factorization of integers as JSON. (sample solution) (solution code) Provide the following behavior: