Consider a practical scenario:
DWR faces confusion when server-side authentication filters redirect AJAX requests to the login page due to expired sessions. Solutions are sought to implement filters that can handle different types of HTTP status codes in various ways.
- For 3xx status codes, execute a client-side redirect like window.location = ...login.html
- If the status code is 2xx, forward the request as is to registered handlers such as DWR.
- Deal with other codes like 4xx by triggering alerts instead of ignoring them.
The need for this type of functionality should be evident; many server-side web frameworks utilize interceptors for similar purposes, which could also benefit clients.
One approach, albeit perhaps flawed, involves wrapping the raw XMLHttpRequest object in a proxy that accepts filter functions. Given that popular libraries like jQuery, Prototype, and ExtJS already wrap native browser AJAX objects, this additional step could be implemented.
Is it feasible to implement this natively? What technical hurdles might arise? Has such functionality been explored before?