Question:
Write code in javascript for developing the creation of node. js server application with a server page named server. js and a client page named index. html.
The client page (index.html) will include with the following field.
Customerid
Firstname
Lastname
Address
City
Province
Postalcode
Requirements:
Allow users to maintain customer data using a web page where maintenance means the ability to add new customers, update existing customer data, delete customers and find a specific customer by customer number (CRUD).
You’ll need to use AJAX to issue post requests (with responses) between the html page and the Node.js server.
It is recommended that you use jQuery AJAX to manage the client-side post requests and response call backs.
UI Requirements:
The New button must clear all the text boxes.
The Add button verifies that all fields have some content and if so, will issue a POST request to the server to attempt to add a new customer record. The POST request will consist of a JSON string containing all the field data. If subsequently, the customer # is found to be not unique, the server will not add the new record and will return a suitable error message. If the customer # is unique, a new file will be created using the customer # + “.txt” as the file name and the JSON string received from the browser as the content – for example” “123.txt”.
The Update button verifies that all fields have some content and if so, will issue a POST request to the server to attempt to update the file for the current customer #. If the file for the customer # does not exist, return an error message otherwise overwrite the file with the new JSON data.
The Delete button will first use the JavaScript “confirm” function to have the user verify the decision to delete the customer. If the deletion is confirmed, take the current customer # and issue a POST request to the server to delete the relevant file. When the response comes back to the browser, clear all fields
The Find button will take the current customer # and issue a POST request to the server to read the JSON string from the file for the current customer and return that string as the response to the browser. The client-side JavaScript will then take the returned JSON, convert it to a JavaScript object and populate all the text boxes.
All files discussed above must be stored in a folder on the server called “data”.
Comments