Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override XMLHttpRequest.prototype.open for ajax calls #156

Closed
barryvdh opened this issue Sep 1, 2014 · 2 comments
Closed

Override XMLHttpRequest.prototype.open for ajax calls #156

barryvdh opened this issue Sep 1, 2014 · 2 comments

Comments

@barryvdh
Copy link
Collaborator

barryvdh commented Sep 1, 2014

Based on the discussion here: symfony/symfony#8896

I'm not sure of support for different browsers etc, but there them seem to override XMLHttpRequest.prototype.open and add an eventlistener to read the header etc. That would mean it doesn't have to depend on jQuery (Angular? #139)

This could also mean that we show some extended information for ajax requests, perhaps a new tab for ajax requests, which also shows the time/status, and a link to load the dataset? And perhaps a toggle to refresh automatically etc.

So instead of bindToJquery, what about something like this:

bindToXHR: function() {
    var self = this;
    var proxied = XMLHttpRequest.prototype.open;
    XMLHttpRequest.prototype.open = function() {
        var xhr = this;
        this.addEventListener("readystatechange", function(method, url) {
            if (xhr.readyState == 4) {
                self.handle(xhr);
            }
        }, false);

        proxied.apply(this, Array.prototype.slice.call(arguments));
    }
}

(That misses the settings object from jquery, not sure how to get that).
Based on work from symfony/symfony#8896

@barryvdh
Copy link
Collaborator Author

So the code from symfony/symfony#12000 is now merged, so might be slightly different. Do you want me to make a PR for this?

@barryvdh
Copy link
Collaborator Author

Closed in favor of #167

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant