Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[JX.Request] Add "open" event

Summary:
Evan was right, it makes sense to have an event that people can listen to to
screw with the transport. Turns out
that many of the transport properties can't be set until after open() has been
called on it, so we need another
hook.

I like this approach more now than I did before because we pass the JX.Request
instance into the callback
instead of the raw XHR. The user can now call getTransport() himself.

Test Plan:
in firebug:

  var r = new JX.Request('test/');
  r.listen('open', function(req) { req.getTransport().withCredentials = true;
});
  r.send();
  r.getTransport()

and inspected the transport. withCredentials was set to true.

Reviewed By: aran
Reviewers: tomo, epriestley, aran
CC: aran, nikolay
Differential Revision: 348
  • Loading branch information...
commit 13c8900c698a8fef03b049fb6470c9da99eb3ca3 1 parent 140e036
@mroch authored
Showing with 7 additions and 3 deletions.
  1. +7 −3 src/lib/Request.js
View
10 src/lib/Request.js
@@ -18,7 +18,7 @@ JX.install('Request', {
}
},
- events : ['send', 'done', 'error', 'finally'],
+ events : ['open', 'send', 'done', 'error', 'finally'],
members : {
@@ -77,8 +77,6 @@ JX.install('Request', {
uri += ((uri.indexOf('?') === -1) ? '?' : '&') + q;
}
- this.invoke('send', this);
-
if (this.getTimeout()) {
this._timer = JX.defer(
JX.bind(
@@ -90,6 +88,10 @@ JX.install('Request', {
xport.open(method, uri, true);
+ // Must happen after xport.open so that listeners can modify the transport
+ // Some transport properties can only be set after the transport is open
+ this.invoke('open', this);
+
if (__DEV__) {
if (this.getFile()) {
if (method != 'POST') {
@@ -106,6 +108,8 @@ JX.install('Request', {
}
}
+ this.invoke('send', this);
+
if (method == 'POST') {
if (this.getFile()) {
xport.send(this.getFile());
Please sign in to comment.
Something went wrong with that request. Please try again.