简体   繁体   English

从 Javascript 读取位于服务器上的属性文件

[英]Read properties file located on server from Javascript

I have a properties file located in my server.我的服务器中有一个属性文件。 Using Javascript or any other client side preferably JQuery, can I load it to fetch values?使用 Javascript 或任何其他客户端,最好是 JQuery,我可以加载它来获取值吗? Is it possible?可能吗?

The standard way to access server-side data from client-side Javascript is to pass it out through a controller on the server, preferably encoded in JSON, and use AJAX on the client side to request it from the server. The standard way to access server-side data from client-side Javascript is to pass it out through a controller on the server, preferably encoded in JSON, and use AJAX on the client side to request it from the server. If you don't need any security, you could possibly just expose the static, flat file from the server instead of making a full controller for it, and parse out the contents in Javascript.如果您不需要任何安全措施,您可以只从服务器公开 static 平面文件,而不是为其制作完整的 controller,然后解析 Z9E13B69D1D2DA927102ACAAAF7154 中的内容。

There is no way to directly access server-side files since in general client-side code can't access the server's private file system.无法直接访问服务器端文件,因为通常客户端代码无法访问服务器的私有文件系统。

If your properties file is accessible through a webserver (for eg: http://your-url/path/to/properties.xml ) then you can simply host a script (http://your-url/path/to/script.html) and fetch the properties file using the AJAX and process it as a XML document (assuming the file is in XML format)如果您的属性文件可以通过网络服务器访问(例如: http://your-url/path/to/properties.xml )那么您可以简单地托管一个脚本(http://your-url/path/to/script .html) 并使用 AJAX 获取属性文件并将其作为 XML 文档处理(假设文件为 XML 格式)

Refer to jQuery documentation on how to parse XML responses and use AJAX Object.请参阅 jQuery 文档,了解如何解析 XML 响应并使用 AJAX Z497031794414A552435F901BAC.

Read this API Doc: http://api.jquery.com/jQuery.ajax/ it has some examples to give you a head start in fetching documents using AJAX Read this API Doc: http://api.jquery.com/jQuery.ajax/ it has some examples to give you a head start in fetching documents using AJAX

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM