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.
Write the JS code to connect to a server-side JSON address book called
addressbook.php
.
Start from this HTML.
(sample solution)
(solution)
addressbook.php
with no parameters outputs an array of names:
{"names": ["Suzie", "Billy", ...]}
name
parameter outputs that person's address:
{"name": "Billy", "address": "123 4th St."}
name
and address
parameter saves that person in the address book.
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:
addressbook.php
with no parameters outputs an array of names:
{"names": ["Suzie", "Billy", ...]}
name
parameter outputs that person's address:
{"name": "Billy", "address": "123 4th St."}
name
and address
parameter saves that person in the address book.
You may assume that any necessary parameters are passed and are in valid formats.
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:
factors.php
with an n
parameter outputs the prime factors of that integer.
For example, the request factors.php?n=264
would output:
<integer value="264"> <factor>2</factor> <factor>2</factor> <factor>2</factor> <factor>3</factor> <factor>11</factor> </integer>
One algorithm for prime factorization of n
is to loop through each integer i from 2-n, and for each time n is divisible by i, add i to your list of prime factors.
n
parameter should return an HTTP error code 400 (Invalid Request) with an instructive error message.
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:
factors.php
with an n
parameter outputs the prime factors of that integer.
For example, the request factors.php?n=264
would output:
{"value": 264, "factors": [2, 2, 2, 3, 11]}
One algorithm for prime factorization of n
is to loop through each integer i from 2-n, and for each time n is divisible by i, add i to your list of prime factors.
n
parameter should return an HTTP error code 400 (Invalid Request) with an instructive error message.