问题描述
我有下面的函数在一个更大的脚本加载的翻译从一个PHP文件:
I have the following function in a much larger script that loads translations from a php file:
function loadLanguages(language){
var data = new Object();
data.language = language;
var dataString = $.toJSON(data);
var langSt = $.ajax({
url: "/VID/ajax/loadtranslations.php",
data: ({data: dataString}),
async: false
}).responseText;
var languageArr = $.evalJSON(langSt);
return languageArr;
}
工作在FF,但在IE7和IE8浏览器将挂起。当我注释掉功能IE不挂Ajax调用。如果我将它设置为异步:真正的功能不工作了,但浏览器不会挂起。只有当我设置异步为false,IE会挂起。我有点疑惑,为什么!
Works in FF, but in IE7 and IE8 the browser will hang.. When I comment out the ajax call in the function IE doesn't hang. If I set it to async: true the function doesn't work anymore, but the browsers will not hang. Only if I set async to false, IE will hang. I'm a bit puzzled why!
推荐答案
您应该使用异步:假
;它将总是挂起浏览器直到请求完成
You should never use async: false
; it will always hang the browser until the request finishes.
这是一个事实的必然结果JavaScript是单线程的,而且永远不会改变。
This is a necessary consequence of the fact that Javascript is single-threaded, and will never change.
这篇关于在使用(得多)与异步Ajax调用IE7挂起:假的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!