function importFile(url, callback) {
var caller = this.caller;
var xmlhttp;
if (window.XMLHttpRequest) {
//針對以下浏覽器:Firefox ,Mozillar ,Opera ,Safari ,IE7 ,IE8
xmlhttp = new XMLHttpRequest();
//針對某些版本的Mozillar浏覽器的BUG進行修正的
if (xmlhttp.overrideMimeType) {
xmlhttp.overrideMimeType("text/html");
}
xmlhttp.open("GET", url, false);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
if (window.execScript) {
window.execScript(xmlhttp.responseText);
} else {
eval.call(window, xmlhttp.responseText);
}
if (typeof(callback) == 'function') {
callback.call(caller);
}
}
};
xmlhttp.send(null);
} else if (window.ActiveXObject) {
//針對IE的各種版本
//将以下各種可用于建立XMLHttpRequest對象的控件名放在數組裡面
var versions = ['Microsoft.XMLHTTP', 'MSXML.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.7.0', 'Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP'];
//嘗試建立XMLHttpRequest對象
for (var i = 0; i < versions.length; i++) {
try {
//如果嘗試建立成功的話,則終止循環
//如果建立失敗的話,則抛出異常,繼續循環,繼續嘗試建立
xmlhttp = new ActiveXObject(versions[i]);
break;
} catch (e) {}
}
xmlhttp.open("GET", url, false);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
if (window.execScript) {
window.execScript(xmlhttp.responseText);
} else {
eval.call(window, xmlhttp.responseText);
}
if (typeof(callback) == 'function') {
callback.call(caller);
}
}
};
xmlhttp.send();
}
}