houenzhen 2009-12-15 11:18
浏览 183
已采纳

ext+struts2.0 同一个action 多个方法 异步问题

一个页面由多个组件组成,每个组件都重后台取数据,使用Ext.Ajax.request()方式

Ext.Ajax.request(
{
url : 'rightAction!methodXX1.action',
}
)

Ext.Ajax.request(
{
url : 'rightAction!methodXX2.action',
}
)

Ext.Ajax.request(
{
url : 'rightAction!methodXX3.action',
}
)



经常1的数据显示在2上,或2的数据显示在3上。

后来把Ext.Ajax.request改为同步方式解决。但同步执行会影响效率,失去ajax的优点。郁闷中……
问题补充:
谢谢boreas_baosj
其实我已经使用同步方法解决了。其实我最主要的是和FusionCharts结合使用。
本来 有setDataURL(XX.action),不能使用,只能使用。
就是感觉有点别扭。

Wsd.web.chart = function() {
var w = 100;
var h = 230;
var obj = document.getElementById('web-area-container');
w = obj.offsetWidth;
w = w / 3;
// 区域
this.showChart(w, h, 'wtoEMsColAction!GZtoGD.action', 'GZtoGD',
'MSColumn3D.swf');
this.showChart(w, h, 'wtoEMsColAction!YNtoGD.action', 'YNtoGD',
'MSColumn3D.swf');
this.showChart(w, h, 'wtoEMsColAction!GXtoGD.action', 'GXtoGD',
'MSColumn3D.swf');
// 地域
var obj = document.getElementById('web-factory-container');
w = obj.offsetWidth;
w = w / 3;
this.showChart(w, h, 'wtoEMsColAction!tianYi.action', 'tianYi',
        'MSColumn3D.swf');
this.showChart(w, h, 'wtoEMsColAction!tianEr.action', 'tianEr',
        'MSColumn3D.swf');
this.showChart(w, h, 'wtoEMsColAction!longTan.action', 'longTan',
        'MSColumn3D.swf');

}
Wsd.web.chart.prototype = {
showChart : function(w, h, url, chartId, swf) {
var xmlStr = Wsd.golob.Synchronize(url);
var chart = new FusionCharts('../scripts/fusionCharts/swf/' + swf,
chartId + '_flash', w, h, '0', '0');
chart.setDataXML(xmlStr);
chart.setTransparent(true);
chart.render(chartId);
}

}

//自己定义一个同步的方法。作为全局的方法使用
Wsd.golob.Synchronize = function(url) {
function createXhrObject() {
var http;
var activeX = ['MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP',
'Microsoft.XMLHTTP'];
try {
http = new XMLHttpRequest();
} catch (e) {
for (var i = 0; i < activeX.length; ++i) {
try {
http = new ActiveXObject(activeX[i]);
break;
} catch (e) {
}
}
} finally {
return http;
}
};

var conn = createXhrObject();
conn.open("GET", url, false);
conn.send(null);
if (conn.responseText != '') {
    var returnVal=conn.responseText;
    if (returnVal.indexOf("Session Expired") != -1) {//判断session超时
        new Wsd.golob.Redirect();
    } else {
        return returnVal;
    }

} else {
    return null;
}

};


  • 写回答

3条回答

  • shijiebao 2009-12-15 14:50
    关注

    LZ的这种情况也是在页面初始的时候吧,在页面初始的时候改成同步是不会有影响的,Ext所有的组件请求都是异步的,LZ可以把1的数据通过同步的方式请求,然后通过设值的方式提供给2,
    [code="javascript"]
    var data_;//全局变量

    //自己封装的ajax请求LZ只要看获得数据的方式
    ajaxRequest(url,参数, function callback(options, success, response) {
    var rs = Ext.decode(response.responseText);
    if (!rs.actionErrors) {
    data_= rs.datas;//获得数据
    } else {
    showErrorMessageBox(rs.actionErrors);
    }
    },false//同步请求的参数
    );

    组件1.setValue(data_);
    组件2.setValue(data_);

    [/code]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大