我使用的是經典的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中動態讀取文本文件中的內容
- 2. 如何閱讀經典的ASP文本文件
- 3. 經典ASP讀取XML文件中的CSV信息
- 4. 從經典ASP讀取ASP.Net Cookie
- 5. 經典ASP獲取文本框的值 - 使用VBScript
- 6. 從文本文件中讀取Javascript
- 7. 經典asp文件包含文件
- 8. Javascript:使用AJAX讀取文本文件
- 9. 使用Javascript讀取文本文件
- 10. 在經典asp中解壓縮文件
- 11. 在經典ASP中創建文件夾
- 12. 經典的ASP和SSL的文件夾
- 13. 動態返回在經典ASP中的JavaScript文件
- 14. 經典的ASP文件列表
- 15. 使用ASP經典
- 16. 經典ASP隨機文字
- 17. 在asp經典腳本塊中使用的Javascript變量
- 18. 用ifstream從文本文件中讀取
- 19. 從URL獲取/讀取文本文件 - 用於After Effects的Javascript
- 20. 使用javascript從文本文件讀取值
- 21. 經典ASP與服務器端的JavaScript,在不同的文件
- 22. 經典asp文件擴展問題
- 23. 批處理文件執行ASP經典
- 24. 下載一個excel文件經典asp
- 25. 經典ASP文件共享問題
- 26. ado打開xlsx文件經典asp
- 27. 無法使用IIS 6.0在經典asp中編寫文件
- 28. 使用javascript從.config文件讀取值
- 29. 用Javascript讀取文本文件?
- 30. 使用javascript讀取文件
可能有幫助,如果逃跑在Windows文件路徑中的反斜槓你可以發佈你的工作VBS例子 – John
你的意思是發球R方JS還是客戶端?那些是完全不同的東西。 –
服務器端JS。 –