Javascript 未调用Microsoft Edge easyXDM on(“消息”)事件
在Microsoft Edge中,GET请求未运行。我已经详细介绍了代码,直到AJAX请求正在运行,并在回调中设置了一个断点。但是,代码永远不会到达回调 我已经有了一个带有回调的.then()和.fail()设置,并尝试添加带有回调的.done()和.always(),但回调中的任何代码都没有运行 然后我检查了devtools中的network选项卡,但根本找不到请求。似乎Edge并没有出于某种原因取消请求Javascript 未调用Microsoft Edge easyXDM on(“消息”)事件,javascript,ajax,microsoft-edge,easyxdm,Javascript,Ajax,Microsoft Edge,Easyxdm,在Microsoft Edge中,GET请求未运行。我已经详细介绍了代码,直到AJAX请求正在运行,并在回调中设置了一个断点。但是,代码永远不会到达回调 我已经有了一个带有回调的.then()和.fail()设置,并尝试添加带有回调的.done()和.always(),但回调中的任何代码都没有运行 然后我检查了devtools中的network选项卡,但根本找不到请求。似乎Edge并没有出于某种原因取消请求 request = function(options, resolveScope) {
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;
}
这就是上面调用请求函数的地方
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
})();
这是cors的东西。(关于这件事我不太了解。)
更新
看来问题已经解决了waitForReady()
未在edge中启动(窗口“消息”,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和mobile Chrome/Safari)。事实证明,以前的开发人员在我们的easyXDM实现中编写了一个必需的“黑客”
在easyXDM的实现中,我们必须更新IE上的窗口
对象,因为我们的应用程序是在iFrame中启动的。由于Edge在技术上不是IE的一个版本,我们的测试失败了,因此代码没有运行以在easyXDM的上下文中将window
更新为window.parent
我们正在使用typeof document.documentMode==“number”
检测IE,但是document.documentMode
在Edge中未定义,因此我们添加了一个navigator.userAgent
检查Edge
这解决了问题。属性不是数据类型不是数据类型吗?不要认为这是个问题,但值得纠正。过去我曾遇到过请求在出错时无法触发的情况。如果将
控制台放在任何地方都不会有任何伤害。记录。完成。失败。然后查看运行的内容。@AntonioManente谢谢您的输入,我会检查一下。啊,对不起,这里输入错误。我已经更新了。还有,有人否决了这个问题,如果你要否决,至少要评论一下你为什么否决它。如果这是一个“愚蠢”的问题,那么答案也会很好…这个window/window.parent修复程序是什么?出于各种原因,我在我的应用程序中检测到Edge,但在easyXDM上下文中运行的将window更新为window.parent的代码是什么?裁判?在任何示例代码段中都没有window.parent代码。谢谢这个问题很老了,我不记得细节了,但是我们的代码在一个iFrame中,所以它可能是对iframes父窗口的引用。
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);
}