A
A
Alexander2015-11-18 17:54:47
JavaScript
Alexander, 2015-11-18 17:54:47

How to intercept all outgoing XMLHttpReques?

At the moment I'm using

(function() {
    var origOpen = XMLHttpRequest.prototype.open;
    XMLHttpRequest.prototype.open = function() {
        console.log('request started!');
        this.addEventListener('load', function() {
            console.log('request completed!');
            console.log(this.readyState); //will always be 4 (ajax is completed successfully)
            console.log(this.responseText); //whatever the response was
        });
        origOpen.apply(this, arguments);
    };
})();

and it basically works until it comes https
here I get news from instagram
$.ajax({
                dataType: "jsonp",
                url: "https://api.instagram.com/v1/users/self/feed",
                data: {
                    count: count,
                    access_token: IG._access_token
                },
                success: function (json) {
                    if(json.meta.code===200)
                        owner.feedBuild(json.data, 'IG');
                }
            });

for what reason does not work?
By the way, when I specify type: "post", the request is still get, explain why.
thank.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
poiuy7, 2015-11-18
@poiuy7

Try with jQuery
But the problem is probably this:
Note: Global events are never fired for cross-domain script or JSONP requests, regardless of the value of global

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question