XMLHttpRequest, ie AJAX, without the XML.(XMLHttpRequest,即AJAX,没有XML。)
The precise manner you do this is dependent on what JavaScript framework you're using, but if we disregard interoperability issues, your code will look something like:(您执行此操作的确切方式取决于您正在使用的JavaScript框架,但如果我们忽略互操作性问题,您的代码将类似于:)
var client = new XMLHttpRequest();
client.open('GET', '/foo.txt');
client.onreadystatechange = function() {
alert(client.responseText);
}
client.send();
Normally speaking, though, XMLHttpRequest isn't available on all platforms, so some fudgery is done.(但是,正常情况下,XMLHttpRequest并非在所有平台上都可用,因此一些软件已经完成。) Once again, your best bet is to use an AJAX framework like jQuery.(再一次,最好的办法是使用像jQuery这样的AJAX框架。)
One extra consideration: this will only work as long as foo.txt is on the same domain.(一个额外的考虑因素:只有当foo.txt位于同一个域时,这才会起作用。) If it's on a different domain, same-origin security policies will prevent you from reading the result.(如果它位于不同的域中,则同源安全策略将阻止您读取结果。) 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…