6

Microsoft Edge では、GET 要求が実行されていません。AJAX リクエストが実行されるポイントまでコードをステップ実行し、コールバックにブレークポイントを設定しました。ただし、コードがコールバックに到達することはありません。

私はすでにコールバックで .then() と .fail() をセットアップしており、コールバックで .done() と .always() を追加しようとしましたが、コールバックのコードはどれも実行されていません。

次に、dev-tools のネットワーク タブを確認しましたが、リクエストがまったく見つかりません。Edge が何らかの理由でリクエストを送信していないようです。

request = function(options, resolveScope) {
    var deferred = $.Deferred();
    corsHandler.makeRequest(options)
        .done(this._wrap(function(response) {
            deferred.resolveWith(resolveScope, [response]); //never gets here
        }, this))
        .fail(this._wrap(function(response) {
            deferred.rejectWith(resolveScope, [response]); //never gets here
        }, this));
    return deferred;
}

これは、上記の request 関数を呼び出すものです。

ajaxFunc = function(data, scope) {
    return request({
        url: '/path/to/server',
        internalUrl: true,
        method: 'GET',
        datatype: 'json',
        data: data
    }, scope);
}

これは、そのリクエストを行うために使用される実装です。

(function() {
    // set data var
    return ajaxFunc(data, self)
        .then(function(res) { console.log(res); }) //never gets here
        .done(function(res) { console.log(res); }) //never gets here
        .fail(function(res) { console.log(res); }) //never gets here
        .finally(function(res) { console.log(res); }) //never gets here
 })();

コルスのネタはこちら。(私はこれについてあまり知りません。)

 corsHandler.makeRequest = function(options) {
        // resolve default options
        _.defaults(options, {
            xhr:        null,
            corsUrl:    null,
            url:        null,
            method:     'GET',
            data:       {},
            success:    function() {},
            error:      function() {},
            terminate:  false,
            binary:     false,
            headers:    {},
            internalUrl: false,
            datatype: ''
        });
        // if url is internal, create absolute url from relative url
        if (options.internalUrl) {
            options.url = this.createAbsoluteInternalUrl(options.url);
        }

        // resolve cors url or proxy url
        options.corsUrl = options.corsUrl || this.getCorsUrl(options.url);
        if (!options.corsUrl) {
            options.url     = this.getProxyUrl(options.url);
            options.corsUrl = this.getCorsUrl(options.url);
        }

        // create xhr
        if (!options.xhr && options.corsUrl) {
            options.xhr = this.createXhr(options.corsUrl);
        }

        // create cleanup procedure
        var cleanUpAfterRequest = $.proxy(function() {
            if (options.terminate) {
                options.xhr.destroy();
                this._removeCacheXhr(options.corsUrl);
            }
        }, this);

        // prepare deffered object
        var deferred = $.Deferred();
        deferred
            .done(function() {
                if (options.success) {
                   options.success.apply(null, Array.prototype.slice.call(arguments));
                }
            })
            .fail(function() {
                if (options.error) {
                    options.error.apply(null, Array.prototype.slice.call(arguments));
                }
            });

        // make actual request
        if (!options.xhr) {
            throw 'corsHandler: xhr object was not created or defined to make request'; 
            // this does not happen
        }
        options.xhr.request(
            {
                url:    options.url,
                method: options.method,
                data:   options.data,
                binary: options.binary,
                headers: options.headers,
                datatype: options.datatype
            },
            function() {
                deferred.resolve.apply(null, Array.prototype.slice.call(arguments));
                cleanUpAfterRequest();
            },
            function() {
                deferred.reject.apply(null, Array.prototype.slice.call(arguments));
                cleanUpAfterRequest();
            }
        );
        return deferred;
    }

アップデート

問題はeasyXDMにあるようです。エッジでwaitForReady()発砲していません。on(window, "message", waitForReady)私は今、この問題をもっと調べています。

easyXDM スニペット:

    targetOrigin = getLocation(config.remote);
    if (config.isHost) {
        // add the event handler for listening
        var waitForReady = function(event){
            if (event.data == config.channel + "-ready") {
                // replace the eventlistener
                callerWindow = ("postMessage" in frame.contentWindow) ? frame.contentWindow : frame.contentWindow.document;
                un(window, "message", waitForReady);
                on(window, "message", _window_onMessage);
                setTimeout(function(){
                    pub.up.callback(true);
                }, 0);
            }
        };
        on(window, "message", waitForReady);

        // set up the iframe
        apply(config.props, {
            src: appendQueryParameters(config.remote, {
                xdm_e: getLocation(location.href),
                xdm_c: config.channel,
                xdm_p: 1 // 1 = PostMessage
            }),
            name: IFRAME_PREFIX + config.channel + "_provider"
        });
        frame = createFrame(config);
    }

上記のスニペットは実行されますが、waitForReadyメソッドは呼び出されません。呼び出されない唯一のブラウザーは Edge です (IE8+、Chrome、Safari、FF、およびモバイル chrome/safari で動作します)。

4

1 に答える 1

0

以前の開発者が私たちの easyXDM の実装に書き込んだ必要な「ハック」があったことが判明しました。

easyXDM の実装ではWindow、アプリが iFrame で起動するため、IE でオブジェクトを更新する必要がありました。Edge は厳密には IE のバージョンではないため、テストは失敗し、コードは実行されず、easyXDM のコンテキストに更新windowされませんでした。window.parent

typeof document.documentMode === 'number'IE の検出に使用していますdocument.documentModeが、Edge では定義されていないため、navigator.userAgentEdge のチェックを追加しました。

これで問題は解決しました。

于 2016-01-15T02:29:32.607 に答える