本文将详细介绍如何将TXT文档中的内容快速准确地导入至各种应用程序的文本框内,帮助用户提升工作效率。
以下是两个文件的代码描述与功能:
第一个文件是 `ajax_txt.asp`:
此页面使用AJAX技术异步提交txt文本段落件路径到另一个名为 `ajax_txt_save.asp` 的页面,并从该页面获取返回的数据。
```html
无标题文档
JS读取文本段落件的内容并赋值给textarea控件
```
第二个文件是 `ajax_txt_save.asp`:
这个ASP页面使用FSO(FileSystemObject)来读取文本段落件中的内容并返回给调用者,即用于支持第一个页面的AJAX异步请求。
```asp
<%
// 禁止缓存该页 让AJAX读取该页始终为最新而非过期缓存页
Response.Expires = 0
Response.Expiresabsolute = Now() - 1
Response.AddHeader pragma,no-cache
Response.AddHeader cache-control,private
Response.CacheControl = no-cache
response.Charset=GB2312
Dim objFSO
Set objFSO = CreateObject(Scripting.FileSystemObject)
ObjFile=trim(request(filesname))
If objFSO.FileExists(ObjFile) then
Set objText = objFSO.OpenTextFile(ObjFile, 1)
k=0
While not objText.AtEndOfStream
strTextContent=strTextContent & objText.ReadLine() & vbcrlf
k=k+1
wend
response.write strTextContent & , & k
else
Response.Write 文件不存在
Response.End()
end if
%>
```
以上代码已经过测试,可以正常工作,并且不受浏览器的安全设置影响。