我有两个AJAX
方法(get_partenaire_convention()
和get_partenaire_contact()
)两种方法都调用Joomla控制器并填充html表
我添加了这两种方法
window.addEvent(\'load\', function() {
get_partenaire_convention();
get_partenaire_contact();
});'
结果不好,
我有一个填充数据的表格汇流而另一个没有,当我改变方法调用的顺序时,我先放get_partenaire_contact()
我填写了表联系人,而另一个没有。
我认为问题在于AJAX的异步调用。
这是ajax电话
function get_partenaire_convention()
{
var id_partenaire = document.getElementById("jform_id").value;
document.getElementById('ajax-partenaire_convention-image_loader').innerHTML = '<img src="components/com_tktransit/images/ajax-loader.gif" width="16" height="16"/>';
if (window.XMLHttpRequest)
xmlhttp=new XMLHttpRequest();
else
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("convention_table").innerHTML = xmlhttp.responseText;
document.getElementById('ajax-partenaire_convention-image_loader').innerHTML = '<img src="components/com_tktransit/images/ajax-blanc.gif"/>';
}
}
xmlhttp.open("GET","index.php?option=com_tktransit&task=partenaire.get_partenaire_convention&id_partenaire="+id_partenaire, true);
xmlhttp.send();
}
答案 0 :(得分:1)
xmlhttp=new XMLHttpRequest();
是一个全局变量
如果另一种方法是全局的,它将覆盖它。
var xmlhttp; //define it so it is not a global
if (window.XMLHttpRequest)
xmlhttp=new XMLHttpRequest();
else
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");