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

2019-03-25 13:38|来源: 网路

一个页面由多个组件组成,每个组件都重后台取数据,使用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;
	}
};


相关问答

更多
  • 该错误是合乎逻辑的:如果您返回错误结果或映射到异常的错误,您仍然会返回成功结果,因为相对的httpheader(statusCode)将始终为200 (成功)。 这只是一个错误,浏览器(因此jQuery回调函数)不能知道它是一个错误的结果。 要输入request.fail(function( jqXHR, textStatus ) { part,您需要发送不同的statusCode( 4xx或5xx ),例如500 (内部服务器错误),否则您将始终输入.done 要在Struts2中执行此操作,您可以使用: ...
  • 可以在action中写多个你需要的方法..然后在struts.xml中为这个action类配置多个 你可以给这些 起不同名字,然后用method属性制定要执行哪个方法...例如: /login.jsp /Login.jsp /welcome.jsp 例如上面的配置就是为LoginAction这个action类配置了2个 而起了不同的名字其中第一个指明了method,用户请求forwardLogin时就会调用LoginAction中的forward()方法第二个没有明了method,用户请求login时就会调 ...
  • Action的async等效是Func ,所以我相信这是你要找的: public async Task DoSomethingAsync(Func resultBody) where T : Result, new() { T result = new T(); await resultBody(result); return result; } The async equivalent of Action is Func
  • public static void Queue(Action action, Action done) { ThreadPool.QueueUserWorkItem(_ => { try { action(); } catch (ThreadAbortException) { /* dont report on this */ } catch (Exception ex) { ...
  • 您还需要在控制器中等待。 经验法则:永远不要说。 .Result ,相反说await 。 您还应该将您的操作方法声明为public async 。 更新:这将是异步调用您的存储库的正确方法。 数据库调用应该并行进行,因为两个任务都是在等待任何事情之前启动的。 您可以通过将调试日志记录放在数据库方法的开头和结尾,并看到“开始1开始2结束1结束2”或类似的内容而不是“开始1结束1开始2结束2”来自己看到这个你的查询速度相当慢。 You need to await in your controller too. ...
  • 你把东西混合起来了。 play.libs.WS用于webservice请求(对某些URL的请求)。 play.libs.F.Promise是(afaik)只是Play 1.x的遗留物 要使用actor,实例化ActorSystem,然后创建一个actor并向他发送消息。 如果你“询问”(actor.ask(...))得到一个结果,你可以使用Await。(现在不知道确切的名称,使用IDE的源代码完成)等待它的响应。 You're mixing things a little up. play.libs.WS ...
  • 实际上里面有几个问题。 Sencha Framework的构建考虑了“一个商店 - 一个视图”的概念。 因此,如果您有两个不同的视图来显示真正的一个数据存储中的信息,那么您仍然需要拥有该存储的两个副本。 如果您不需要同时显示这两个视图,则可以清除/应用过滤器(对于电话应用程序,这通常是正确的),但我建议您有两个单独的副本。 就你的情况而言 - 我认为你不需要那样。 当您显示特定书籍时,您不需要过滤商店。 您只需加载一条记录( store.getAt() ),然后在子表单中使用此记录。 There are a ...
  • 添加一个循环,等待计数器达到你的asyncs计数值,并让每个异步增加这个计数onPost I ended up creating a Service instead of a IntentService just like CommonWare suggested in a comment. Following this example and putting the handling of data inside of separate thread.
  • 您可以使用线程模块使用Timer命令调用该方法: from functools import partial import threading class While_True(threading.Thread): def __init__(self, **kwargs): threading.Thread.__init__(self) def whileTrue(self, *args): print args def caller( ...
  • 您需要同步调用该方法,或使用await 。 例如: 同步( GetEmployee()将阻塞,直到GetSomeEmployee()完成): public IHttpActionResult GetEmployee() { // Get employee info Employee emp = myDataMethod.GetSomeEmployee().Result; return Ok(emp); } 异步( GetEmployee()将立即返回,然后在GetSomeEmploy ...