问题描述
如何使用Ajax从远程计算机(从IIS6.0虚拟目录)读取文件(.txt/.xml)中的文本,或者将其复制到客户端计算机的"TEMP/specified"文件夹中.
how can I read the text in the file(.txt/.xml) from remote machine(from IIS6.0 Virtual directory) either using Ajax and copy into client machine 'TEMP/specified' Folder.
应执行以下步骤,在单击按钮:1)请求应转到服务器(它是ASP.NET3.5应用程序,并托管在IIS6.0中)2)打开文件(.txt/.xml)并读取全部内容,然后传递给客户端计算机.3)获取(读取)内容并将其复制到客户端计算机指定的路径(可以是TEMP文件夹或指定的文件夹)中.
Following steps should happen, On Click upon the button:1) request should go to the server( it is ASP.NET3.5 application and hosted in IIS6.0)2) open the file(.txt/.xml) and read the full content then pass to the client machine.3) Take(read) the content and copied in client machine specified path (it may be TEMP folder or specified Folder).
如果提供相同的示例代码,那将非常好
It would be really great if any sample code is provided for the same
谢谢
推荐答案
<script type="text/javascript">
var http = false;
if(navigator.appName == "Microsoft Internet Explorer") {
http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
http = new XMLHttpRequest();
}
http.open("GET", "test.txt");
http.onreadystatechange=function() {
if(http.readyState == 4) {
alert(http.responseText);
}
}
http.send(null);
</script>
P.S.您实际上无法将文件保存到本地客户端的计算机上
P.S. You cannot actually save a file to local client's machine
这篇关于从远程计算机读取文件(.txt/.xml)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!