What is the purpose of using AJAX in a poll application?
A
To reload the entire page after voting
B
To submit and retrieve poll data without refreshing the page
D
To store JavaScript functions
Analysis & Theory
AJAX allows users to vote and view updated poll results without refreshing the page.
Which JavaScript object is commonly used to send AJAX requests for a poll?
Analysis & Theory
`XMLHttpRequest` is used to send asynchronous requests to the server for submitting votes or fetching results.
What is typically stored in the backend database for a poll?
B
Vote counts and poll options
Analysis & Theory
The database stores poll options and their respective vote counts.
What SQL command updates the vote count when a user votes?
Analysis & Theory
An `UPDATE` statement is used to increment the vote count for the selected poll option.
Which event is commonly used to trigger an AJAX call when a user selects a poll option?
Analysis & Theory
Either `onchange` for radio buttons or `onclick` for buttons triggers the AJAX call.
What type of response is typically returned from the PHP file in an AJAX poll?
B
JSON or HTML with updated poll results
Analysis & Theory
The PHP file returns JSON or HTML containing the updated vote counts and percentages.
What is the purpose of the `onreadystatechange` property in XMLHttpRequest for a poll?
A
To submit the vote to the server
B
To detect when the server responds with updated poll data
Analysis & Theory
It listens for changes in the request state and processes the server's response when ready.
What HTTP method is commonly used in AJAX for submitting a poll vote?
Analysis & Theory
`POST` is typically used to securely submit the selected poll option to the server.
Why is AJAX preferred in polls over traditional form submission?
A
It requires less PHP code
B
It refreshes the page automatically
C
It allows dynamic vote submission and result updates without reloading the page
Analysis & Theory
AJAX enables real-time vote updates and results display without reloading the page.
What happens if multiple users vote simultaneously in an AJAX poll?
A
Only the first vote is recorded
C
The server updates each vote individually and reflects it in the poll result dynamically
Analysis & Theory
Each vote triggers a server-side update, and AJAX retrieves the updated results dynamically for all users.