mobify/hijax — pull request #1 by donnielrt (2014-05-20 21:38:29+00:00)
Title: Hijax XHR proxy

Hijax XHR proxy

Status: **Opened for visibility**

Reviewers: @jansepar @scalvert @tedtate @kbingman @noahadams @MikeKlemarewski

## Introduction
- The XHR proxy overwrites a couple of key XMLHttpRequest methods with a custom proxied version. This allows hooking on to AJAX send/receive methods independently of the library used.
- Assumes that the library uses the XMLHttpRequest as the transport. Proxies the xhr instance __onreadystatechanged__ method to proxy code. If not found, attaches to the xhr __readystatechange__ event. This is needed for jQuery, for example, which sets the __onreadystatechange__ handler __after__ it launches a send request.
- Provides three events: **.beforeSend**, **.receive** and **.complete**. All three have the XHR instance as their only argument. We could possibly provide the data (responseText) directly, but then we'd need to account for MIME types. For example, jQuery responds to JSON, Script, Text, XML, etc. data differently.

## How to test-drive this PR
- `grunt serve` and go to localhost:8888/example and check your console. You'll note that the jQuery AJAX event has been intercepted
- (Optional) Try swapping out jQuery for another library to ensure XHR is still intercepted

## Research resources
- https://developer.mozilla.org/en/docs/Web/API/XMLHttpRequest
- http://api.jquery.com/jquery.ajax/