Read properties file located on server from Javascript
I have a prop开发者_如何学Pythonerties file located in my server. Using Javascript or any other client side preferably JQuery, can I load it to fetch values? 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. 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.
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)
Refer to jQuery documentation on how to parse XML responses and use AJAX Object.
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
精彩评论