Dealing with XHR requests
Asynchronous JavaScript XMLHttpRequest (XHR), commonly known as Ajax, has become an important part of web applications over the last few years. With the advent of one-page applications and JavaScript application frameworks such as AngularJS, BackboneJS, and more, this technique of web development has risen exponentially.
Getting ready
Flask provides an easy way to handle the XHR requests in the view handlers. We can even have common methods for normal web requests and XHRs. We can just look for a flag on our request
object to determine the type of call and act accordingly.
We will update the catalog application from the previous recipe to have a feature that will demonstrate XHR requests.
How to do it…
The Flask request
Get Flask Framework Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.