0

This is my ajax funcion

var XMLHttpRequestObject = false;
if(window.XMLHttpRequest){
    XMLHttpRequestObject= new XMLHttpRequest();
} 
else if (window.ActiveXObject){
    XMLHttpRequestObject= new ActiveXObject("Microsoft.XMLHTTP");
}

function getData(dataSource, divID)
{
    document.getElementById(divID).innerHTML = "Loading...";
    if(XMLHttpRequestObject)
    {
        var obj=document.getElementById(divID);
        //alert(dataSource);
        var dataSource = dataSource+'&done=ok';
        XMLHttpRequestObject.open("GET", dataSource);
        XMLHttpRequestObject.onreadystatechange =function ()
        {
            if(XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200){
                obj.innerHTML = XMLHttpRequestObject.responseText; 
                document.getElementById(divID).innerHTML=XMLHttpRequestObject.responseText;
            } //else {alert ('error'+dataSource)}
        }

        XMLHttpRequestObject.send(null);

    }
}

and this is another function call above ajax function twice:

function getCityResult(value){
    getData('aids/getRoutAjax.php?city='+value , 'rout');
    getData('aids/getOriginDestAjax.php?city='+value , 'OriginDest');
}

and i have select menu as following:

<select name="city_id" id="city_id" class="" style="width:300px;" onchange="return getCityResult(this.value);">
    <option value="">Select</option>
    <option value="13">ABQ</option>
    <option value="12">MUB</option>
    <option value="14">UDH</option>
</select>

<div id="rout"> 
    //Show some data
</div>
<div id="OriginDest">
    // Show some data
</div>

my result is calling first one only to show data on div with id [rout] How can i call both on same time by this way??

Thanks

4

1 回答 1

0

这两个都应该被调用,如果你的代码在 getOriginDestAjax.php 中是正确的,它没有理由只适用于第一个。为了确定这一点,请尝试在同一页面上调用两者:

getData('aids/getRoutAjax.php?city='+value , 'rout');
getData('aids/getRoutAjax.php?city='+value , 'OriginDest');
于 2012-07-31T14:17:47.227 回答