Ajax请求和回调更新正在引发在同一时间回调、时间、在同一、Ajax

由网友(浪子无家)分享简介:我有一些提交被以下面的方式定义的按钮:I have some submit buttons that are defined in the following manner:我有一些提交被以下面的方式定义的按钮:

I have some submit buttons that are defined in the following manner:

<input id="add_200,231" type="submit" onclick="updatePage(401,27371,200,231)" value="Add"/>

相应的引用的JavaScript函数的onclick看起来是这样的:

The corresponding javascript function referenced in "onclick" looks like this :

function updatePage(slac,sci,tlac,tci) {
	var url = '/neighbouring?.state=add_cell&source=' + slac + ',' + sci +'&target='+ tlac + ',' + tci + '&dummy='+(new Date()).getTime();

	new Ajax.Request(url,{
		onComplete: triggerContentUpdate(slac,sci)		
	});
}

function triggerContentUpdate(slac,sci) {
	var updates = document.getElementsByClassName('update_on_add');
	for (var i = 0; i < updates.length; i++) {
		var uid = updates[i].id;
		var url = '/neighbouring?.state=update_template&divid=' + uid + '&source='+slac + ',' +sci + '&dummy='+(new Date()).getTime();
		var uAjax = new Ajax.Updater(uid,url,{ method: 'get'});

	}
}

这需要更新被标记为update_on_add类的标签。

The elements that need to be updated are tagged with "update_on_add" class tags.

当使用萤火虫,我可以看到,所述的Ajax.Request中的updatePage()以及Ajax.Update在triggerContentUpdate()函数调用同时。我本来期望triggerContentUpdate()仅被调用后的Ajax.Request完成。

When using Firebug, i can see that the Ajax.Request in updatePage() as well as the Ajax.Update in the triggerContentUpdate() functions are called at the same time. I would have expected triggerContentUpdate() to only be called after Ajax.Request has completed.

我失去了一些东西呢?

推荐答案

您行

onComplete: triggerContentUpdate(slac,sci)

onComplete: function() { triggerContentUpdate(slac,sci); }

您会立即调用该函数,并指派其返回值的的onComplete成员。

You're calling the function immediately and assigning its return value to the onComplete member.

阅读全文

相关推荐

最新文章