Hong Kong Baptist University · FACULTY OF COMPUTER SCIENCE

AIDM7450 Chap.7 Forms, AJAX and RESTful Services

- one subject, every graph, every model, every mark
7 Chapters4-page Bible
Our own words - no uploaded lecturer files
Updated for this semester
Chapter 7 of 7 · AIDM7450

Forms, AJAX and RESTful Services

One value across several boundaries

Form controls collect values, and their name attributes carry those values into request data. This chapter follows a submitted field through the POST body, parser and Express handler, then compares complete-page navigation with an AJAX request that updates one region.

RESTful services keep resources addressable, use a uniform method interface, communicate through representations and keep requests stateless. The clinic method classifies failures as payload, route, data, response or DOM defects before changing code.

Control type expresses the data relationship: radio buttons sharing a name offer alternatives for one field, while checkboxes can represent independent choices.

A normal form submission still provides the baseline for method, action, payload and response. AJAX changes who handles the response and how much of the document is replaced; it does not remove HTTP. In a resource-centred interface, the URI identifies a story or collection, the method identifies the operation, the representation carries state and each request supplies what the server needs to understand it.

In this chapter

What this chapter covers

  • 01

    Form controls and field names

  • 02

    Radio, checkbox and button choice semantics

  • 03

    POST body parsing in Express

  • 04

    Normal navigation and partial AJAX updates

  • 05

    Addressable REST resources

  • 06

    Stateless request design

  • 07

    GET, POST, PUT and DELETE operation mapping

Worked example · free

Repair a search form and update scope

Q [10 marks]. AskSia-authored practice. A form sends a field named query, the handler reads term, and a normal response replaces the page although the designer wanted one panel updated. Repair both contracts. The marks shown are an AskSia study allocation.
The left panel replaces the complete page while the right updates one region.The left panel replaces the complete page while the right updates one region. The highlighted rectangle marks the smaller AJAX replacement scope.Two requests, different replacement scopesNormal submissionreplace complete pageAJAX requestreplace changed region
The left panel replaces the complete page while the right updates one region. The highlighted rectangle marks the smaller AJAX replacement scope.
  • 3Align the field name with the request-body key.
  • 3Prevent default navigation and send one asynchronous request.
  • 4Parse the response and replace the intended panel.
This guide's marks here support practice and are not an official university marking scheme. Rename the input or change the handler so both use the same key, then verify the parser matches the submitted representation. Intercept submission, prevent the default navigation and send one asynchronous request to the existing route. Parse the returned representation, select the results panel and replace or reconcile its old state. Handle failure visibly so stale results do not appear current.
Sia tip — A visible field without the expected name arrives as no usable value. Inspect the payload before changing the route.
Glossary

Key terms

Form Control
An input, button, selection or text area through which a user supplies or submits a value.
Field Name
The key that identifies a form value to JavaScript and server-side processing.
Request Body
The portion of a request carrying submitted representation data for the server to parse.
AJAX
Asynchronous browser communication that can update one region without replacing the complete document.
REST Resource
An addressable item or collection manipulated through a uniform service interface.
Stateless Request
A request carrying the information needed to understand it without hidden conversational context.
FAQ

Forms, AJAX and RESTful Services FAQ

Why do radio buttons share one name?

A shared name makes the buttons alternatives for one field, so the request carries one selected value. Different names represent independent fields and may submit several values. Keep distinct value attributes while sharing the field name for the choice group.

Does AJAX replace HTTP?

No. An AJAX call still sends an HTTP request and receives a status, headers and body. The difference is that client code receives the response asynchronously and can update a selected region instead of letting the browser replace the complete document.

What makes an interface RESTful in this course?

Information is treated as addressable resources, methods provide a uniform operation interface, representations carry state, requests are stateless and links can guide state changes. GET retrieves, POST creates, PUT updates and DELETE removes within the taught CRUD mapping.

Study strategy

Exam move

Draw one form value from its control name through the request body, parser, handler and response. Then send the same operation normally and asynchronously and compare what the browser replaces. Finish by redesigning action-named routes around stable resource URIs and HTTP methods. For every exercise, inspect payload, status, representation and final DOM state rather than relying on the screen alone.

Build a control table with visible label, type, name, submitted value and expected server key. Include one radio group, independent checkboxes, a disabled field and a hidden field, then predict the payload before submitting it. Verify that the parser is configured for the representation actually sent.

Run the search once as normal navigation and once with the default action prevented; count requests and record whether the complete document or one selected panel changes. Force an error and ensure stale results are not left looking current. Redesign `/removeStory/42` as a stable story resource with an operation expressed by the HTTP method, then map retrieval, creation, update and deletion consistently.

For each request, state what makes it self-contained and which representation returns. Finish by changing one boundary at a time so a missing field, unmatched route, invalid response or wrong DOM target produces distinguishable evidence. Add a repeated-submission test and confirm that handler lifetime, request count and rendering strategy cannot duplicate cards when the same filter is used twice.

Working through Forms, AJAX and RESTful Services in AIDM7450? Sia is AskSia’s AI Computer Science tutor — ask any AIDM7450 Forms, AJAX and RESTful Services question and get a clear, step-by-step explanation grounded in how AIDM7450 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.

A+Everything unlocked
Unlocks this Bible + all 16 of your subjects at Hong Kong Baptist University, plus 1,000+ more Bibles across the AskSia library.
Sia - your AIDM7450 tutor, unlimited, worked the way the exam marks it
The full 4-page Bible + practice bank with worked solutions
Chrome extension - sync your LMS so Sia knows your deadlines
Bilingual EN / Chinese on every Bible and every Sia answer
$0.99 Trial
30-day money-back · cancel in one tap · how it works