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返回值是真实的后才执行下面的代码呢?替代的方法也可以。
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返回值是真实的后才执行下面的代码呢?替代的方法也可以。
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;
}
});
{
data是返回的数据即xmlHttp.responseText
if(data.substring(0,3)=="yes")
{
...
}
}