Firefox中的同步AJAX请求焦点错误元素 [英] Synchronous AJAX request focus wrong element in Firefox

查看:80
本文介绍了Firefox中的同步AJAX请求焦点错误元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的错误,我不明白怎么了.如果在事件处理程序中执行同步AJAX请求,则在我的应用程序中处理 TAB 键时,Firefox会将焦点集中在错误的元素上.

I'm having a strange bug and I don't understand what's going wrong. When handling TAB key in my application Firefox will give focus to a wrong element if I perform a synchronous AJAX request in the event handler.

我设法在此处生成了一个简单的测试用例: http://jsfiddle.net/aVeQp/18/

I managed to produce a simple test case here : http://jsfiddle.net/aVeQp/18/

如果单击结果部分,然后按Tab键,则前两次将正常工作(转到下一个单元格),但最后一次将焦点放在"home"元素上.如果将查询更改为异步,则焦点不会转到主页按钮.

If you click on the result part and then press tab, the first two times it works properly (goes to the next cell), but the last time, it gives focus to the "home" element. If you change the query to be async the focus does not go to the home button.

var ret = $.ajax({
            type: 'POST',
            url: "",
            data: { action: "test"},
            datatype: "xml",
            async: false
            });

在Linux下不会发生这种情况,但是我在Windows 7 64位下遇到了Firefox 16.0.2的错误.

This does not happen under Linux but I have the bug with Firefox 16.0.2 under Windows 7 64bits.

我知道ajax调用在jsfiddle上无法正常工作,但该错误发生在我自己的安装中,而ajax调用正确返回,只是为了显示代码和错误.我尝试使用dhtmlx的AJAX请求,并且发生了相同的错误.

I know that ajax calls are not working properly on jsfiddle but the bug happens on my own installation with the ajax call returning properly it is just to show the code and the bug. I tried using dhtmlx's AJAX request and the same bug happens.

有人知道我在做什么错吗?我已经尝试了很多事情,在这种特定情况下,firefox似乎并不关心停止事件的传播.

Does anyone have a clue what I'm doing wrong? I've tried a lot of things, it seems that firefox does not care about stopping the propagation of the event in this specific case.

似乎我在以前的测试中做错了什么,而setTimeout()最终是一个可行的解决方案. 但我仍然认为,最后没有这种"hack"应该可以解决问题.

Seems that I did something wrong in my previous tests and setTimeout() is a working solution in the end. But I still thinks it should work without this "hack" in the end.

推荐答案

我没有需要复制的环境,但是我有一个长远的建议可能对您有用.尝试将ajax调用包装在其中

I dont have the required environment to replicate but i have a longshot suggestion that might work for you. Try wrapping the ajax call inside

setTimeout(function(){您在这里的电话},1);

setTimeout(function() { your call here}, 1);

看看进展如何.

将回调绑定到ajax

Binding callback to the ajax

$.ajax().done(function(data){console.log(data);});

$.ajax().done(function (data) { console.log(data); });

这篇关于Firefox中的同步AJAX请求焦点错误元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆