How do you make an AJAX request using jQuery?

Instruction: Provide an example of making a simple GET request to an API endpoint using jQuery.

Context: This question tests the candidate's ability to utilize jQuery for asynchronous HTTP requests, a critical component of dynamic web applications.

Updated

Official answer available

Read the opening below, then unlock the full answer and practical guidance.

Use $.ajax from the full jQuery build. Specify the request method, endpoint, expected response format and failure behavior. Ajax does not bypass server authorization or browser cross-origin restrictions.

This example expects a same-origin GET endpoint at /api/people to return an object containing a people array of at most 50 objects, each with a string name. This assumes the document has no cross-origin base URL: a base element can change how the root-relative endpoint is resolved...

Related Questions