11 Client-side technologies and AJAX
This chapter covers
- Choosing your client-side technology
- Calling page handlers from client-side code
- Working with JSON in Razor Pages
- Isolating CSS styles on a per-page basis
All the code examples that we have worked with have relied on the HTML for the page being generated in full on the server, except in one area - client-side validation. The validation error messages were generated using client-side libraries, specifically Microsoft’s jQuery Unobtrusive Validation library. As a feature, client-side validation enhances the usability of the website. It gives users instant feedback on form validation errors without waiting for the entire form to be submitted to the server for processing.
Usability is critical if you want to keep your users happy, and usability can be improved dramatically in server-side applications using client-side technologies. In this chapter, we will look at how to implement some common patterns that use client-side technologies within a Razor Pages application. Since it is included as part of the default project template, we will look at jQuery for DOM manipulation and for making asynchronous HTTP requests initiated by the browser. We will also explore alternatives using plain JavaScript and consider the future of jQuery.