function upload(){
var str=getApi('','');
alert(str);
alert(111111111111111);
}//获取API
function getApi(){
$.ajax({
    url: "index.php?t="+(new Date()).valueOf(),
    type: 'GET',
    dataType: 'xmlDoc',
    timeout: 5000,
    error:function(){alert("载入出错了!");},
    success:function(xmlDoc){
     return xmlDoc;
    }
});//开始
upload();/////////////////////////////////////
因为获取到这个Ajax的返回值的花费的时间很长,如何才可以在等到这个Ajax返回值是真实的后才执行下面的代码呢?替代的方法也可以。

解决方案 »

  1.   

    //获取API 
    function getApi(){ 
    $.ajax({ 
        url: "index.php?t="+(new Date()).valueOf(), 
        type: 'GET', 
        dataType: 'xmlDoc', 
        timeout: 5000, 
        error:function(){alert("载入出错了!");}, 
        success:function(xmlDoc){ 
    upload();//这里放代码在返回后才执行
        return xmlDoc; 
        } 
    }); 
      

  2.   

    看着是jQuery的代码吧?我用得少,不过看名字sucess应该就是AJAX成功返回后会被调用的函数。所以像楼上那样放里面就行了。另外我没明白return xmlDoc是怎么回事,貌似没有人能够收到你这个xmlDoc
      

  3.   

    success:function(data)
    {
    data是返回的数据即xmlHttp.responseText
    if(data.substring(0,3)=="yes")
    {
    ...
    }
    }