Making AJAX Requests

Let's see how an AJAX constructor behaves differently from the observables and throws an error if the URL doesn't exist.

We'll cover the following

ajax constructor

ajax is another helper constructor; this one performs an AJAX request.

It returns an observable of a single value: whatever the AJAX request returns. Here’s a simple example.

Note: The ajax constructor is imported from a different location than the other constructors.

Running this code does not log data about the AJAX request to the Console. Instead, a big fat error message appears in the Console informing us that the URL, I told you to request doesn’t exist.

Get hands-on with 1200+ tech skills courses.