52,798
社区成员
发帖
与我相关
我的任务
分享
function text()
{
ajax(function (data) {
var x = data;
document.getElementById("txt1").innerHTML= x;
............后续操作都在回调函数中.........
});
}
function ajax (callback) {
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
}
else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("get","file.txt",true);
xmlhttp.send();
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4)
{
if(xmlhttp.status==200)
{
document.getElementById("txt1").innerHTML= xmlhttp.responseText;
callback(xmlhttp.responseText);
}
else{
alert("读取失败");
}
}
}
ajax(function (data) {
var x = data;
});