使用javascript函数检查文件夹中是否存在.txt文件。如果文件存在则自动重新加载页面 [英] Check whether .txt file exists or not in the folder using javascript function.If file exists reload the page automatically

查看:83
本文介绍了使用javascript函数检查文件夹中是否存在.txt文件。如果文件存在则自动重新加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我想使用Javascript检查特定文件夹中是否存在.txt文件。如果文本文件存在那么我会喜欢重新加载页面。



请把这个场景的示例代码发给我。



谢谢!

Hi,

I would like to check the whether the .txt file exists or not in the particular folder using Javascript.If text file exists Then I would to like to reload the page.

Please send me the sample code for this scenario.

Thanks!

推荐答案

正如Richard所说,JavaScript无法访问本地客户端的PC文件系统。这将是一个巨大的安全风险。



但是,如果您指的是服务器,那么您可以使用jQuery的.ajax()方法, jQuery.ajax()| jQuery API文档 [ ^ ]来调用web服务检查服务器上的文件系统并返回相应的响应。



注意,如果您正在检查服务器,则需要确保显示的帐户为IIS中应用程序池的标识需要文件系统的权限,否则检查将始终返回false。
As Richard mentioned, JavaScript cannot access the local client's PC's file system. That would be a huge security risk.

However, if you are referring to the server then you can use jQuery's .ajax() method, jQuery.ajax() | jQuery API Documentation[^] to call a webservice that checks the file system on the server and returns an appropriate response.

Note, if you are checking the server you'll need to make sure the account shown as the identity of the application pool in IIS will need permissions to the file system or else it checking will always return false.


这篇关于使用javascript函数检查文件夹中是否存在.txt文件。如果文件存在则自动重新加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆