我使用的是经典的ASP,并试图将特定文本文件的内容打印到屏幕上。我知道如何通过ASP在VBScript中做到这一点,但是如何通过ASP在JavaScript中做到这一点?从使用Javascript的经典ASP文件中读取文本
1
A
回答
1
如果你使用普通的JavaScript,你可以做如下的事情。请记住,将get函数的第一个参数替换为实际的文件路径,包括文件扩展名(例如:myfilename.txt)。您还必须确保您尝试打开的文件来自同一个域。这里是一个如何工作的例子的链接(http://bytewarestudios.com/launchjs/get)。我从我写的JavaScript库中删除了get函数,因此您不必加载整个库。
HTML:
<div id="results"></div>
的JavaScript(将此代码的脚本标签的结束标记前右):
//call the get function
get(pathToTextFile,function(data){
//display the file contents to the screen.
document.getElementById("results").innerHTML = data;
});
function get(url,fn){//begin ajax function
var contentType;
//variable to hold the xmlhttp object
var xmlhttp = null;
//if a contentType is not passed in
if(typeof arguments[1] === "function"){//begin if then else
//set it to default of text/html
contentType = "text/html";
}//end if then
else{
//set the contentType to the argument passed in
contentType = arguments[1];
}//end if then else
//if the browser contains the object
if(window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
//create a new XMLHttpRequest object
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
//create a new ActiveXObject
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}//end if then else
//add the event listenter
xmlhttp.onreadystatechange = function(){
//if the status of the request is good
if (xmlhttp.readyState===4 && xmlhttp.status===200){//begin if then
//get the response text and store it in the data variable
var data = xmlhttp.responseText;
//call the ajaxDone callback function
ajaxDone(data,fn);
}//end if then
};//end function
function ajaxDone(data,fn){//begin function
//call the anonymous function passing the data returned from the xmlhttp request
fn(data);
}//end function
1
它基本上只是翻译您的VBS成JS的情况下,它的没有那么难,只要你对这两方面有基本的了解。
VBScript示例
<%@ LANGUAGE="VBSCRIPT" %>
<%
dim fso, txt, content
set fso = Server.CreateObject("Scripting.FilesystemObject")
set txt = fso.OpenTextFile("C:\Pathto\textfile.txt")
content = txt.ReadAll
Response.Write content
%>
JScript的例子
<%@ LANGUAGE="JSCRIPT" %>
<%
var fso = Server.CreateObject("Scripting.FileSystemObject");
var txt = fso.OpenTextFile("C:\\Pathto\\textfile.txt");
var content = txt.ReadAll();
Response.Write(content);
%>
请注意,你需要,如果你正在使用JS
相关问题
- 1. 从经典ASP中的PDF文件读取数据
- 2. 阅读XML文件的经典ASP
- 3. 在ASP经典文件中编写JavaScript
- 4. 标题:在经典asp中动态读取文本文件中的内容
- 5. 如何阅读经典的ASP文本文件
- 6. 经典ASP读取XML文件中的CSV信息
- 7. 从经典ASP读取ASP.Net Cookie
- 8. ASP经典下载文件脚本
- 9. 从.jar读取字典文本文件
- 10. 使用Javascript编写ASP风格的cookie(带键);使用经典ASP读取
- 11. 读取和写入数据的Excel文件经典ASP
- 12. 经典ASP获取文本框的值 - 使用VBScript
- 13. 从文本文件中读取Javascript
- 14. 经典asp文件包含文件
- 15. 经典的ASP + Javascript
- 16. 在经典ASP中读取ServerXMLHTTP请求
- 17. 在经典ASP中读取XML
- 18. Javascript:使用AJAX读取文本文件
- 19. 使用Javascript读取文本文件
- 20. 使用Javascript读取文本文件
- 21. 从本地JavaScript文件中读取本地文本文件?
- 22. 在经典asp中解压缩文件
- 23. 在经典ASP中创建文件夹
- 24. Base64使用经典ASP和VB脚本编码ZIP文件
- 25. 经典的ASP读取XML值
- 26. 经典的ASP和SSL的文件夹
- 27. 动态返回在经典ASP中的JavaScript文件
- 28. 使用javascript的经典ASP写会话
- 29. 经典的ASP文件列表
- 30. 使用ASP经典
可能有帮助,如果逃跑在Windows文件路径中的反斜杠你可以发布你的工作VBS例子 – John
你的意思是发球R方JS还是客户端?那些是完全不同的东西。 –
服务器端JS。 –