ext-basex.js处理的同步请求在Firefox12中不支持(在Firefox11中是支持的)怎么办?(已解答)

来源:互联网 发布:大数据分析模型 包括 编辑:程序博客网 时间:2024/05/21 11:15

Ext.Ajax.request发送同步请求---基于ext-basex

 

首先从http://code.google.com/p/ext-basex/下载ext-basex 脚本文件,解压后按照说明readme文件的方法引用EXT库和ext-basex。

<head>
<link rel="stylesheet" type="text/css" href="../lib/ext-3.0+/resources/css/ext-all.css" />
<script type="text/javascript" src="../lib/ext-3.0+/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="../lib/ext-3.0+/ext-all[-debug].js"></script>
<script type="text/javascript" src="../lib/ux/ext-basex[-debug].js"></script>
</head>

然后使用Ext.Ajax.request方法,添加 async: false,   //ASYNC 是否异步( TRUE 异步 , FALSE 同步),其他参数不变。

        Ext.Ajax.request({
            url: "StreamingProxy.ashx",   
            method: "GET",
          async: false,   //ASYNC 是否异步( TRUE 异步 , FALSE 同步)
            success: function(response, opts) {
            }, //请求成功的回调函数
            failure: function() { alert("获取目录请求失败!"); } // 请求失败的回调函数
        });

 

 

注意:做了以上操作后在IE、google chrome、firefox11下是没有问题的,但到了firefox12下去看,就发现执行这个的时候一直执行的是失败,也就是走到failure中去了。

 

Ext.Ajax.request({
url : 'UserValidate',
method : 'post',
params : {
type : 'checksession'
},
async : false, // async 是否异步( true 异步 , false 同步)
success : function(response, opts) {
alert('response.responseText:'+response.responseText);
var val = Ext.util.JSON.decode(response.responseText);
if (val.nosession) {
window.location.href = "index.html";
return;
}
},
failure : function(response,options) {
alert('4444444444444444444444444');
alert('failure response.responseText:'+response.responseText);
window.location.href = "index.html";
return;
}
});

如果加上“async : false, // async 是否异步( true 异步 , false 同步)”则在firefox中无法执行EXt.ajax.request请求,也就是老跑到failure中去,这个同步是要加上ext-basex.js的。

 

 

 

 

解决办法:

修改ext-basex-debug.js文件中的一条语句:

将以下代码:

if(callback && callback.timeout){

改为:

if(callback && callback.timeout && options.async){

正如大家看到的一样,添加了“&& options.async”。

 

改完上面的地方就可以了。

 

如果你不是使用的debug版,使用的是压缩的版本,那么在ext-basex.js中查找“if(u&&u.timeout){”(注意不含引号),找到后修改为“if(u&&u.timeout&&n.async){”,当然,你可以直接替换。

结论:

将“if(u&&u.timeout){”改为“if(u&&u.timeout&&n.async){”。

 

注意:测试的时候一定要先清理一下缓存,我试的时候一直没有效果,后来发现是缓存原因。

怎样清理浏览器缓存[各种浏览器]       

http://blog.csdn.net/e_wsq/article/details/7521468

 

也有人说改另一个地方,不过我没有试,上面是我试了没有问题的。

 

in ext-basex.js 4.1 about line 1011
('timeout' in r) && (r.timeout = callback.timeout);
modified to :
(options.async) && ('timeout' in r) && (r.timeout = callback.timeout);

原创粉丝点击