简体   繁体   English

如何使用jQuery / JavaScript将子文件夹中的所有文件名加载到我的安全网页中

[英]How to load all the file names from a sub folder into my secure web page, using jQuery/JavaScript

I have a sub folder named "images". 我有一个名为“ images”的子文件夹。 I want to load all the file names from "images" folder into my html page using jQuery/JavaScript on a secure web site. 我想使用安全网站上的jQuery / JavaScript将“ images”文件夹中的所有文件名加载到html页面中。

How can I do this? 我怎样才能做到这一点?

I know how to do this for an unsecured site: How to load all the images from one of my folder into my web page, using Jquery/Javascript 我知道如何针对不安全的网站执行此操作: 如何使用Jquery / Javascript将文件夹中的所有图像加载到我的网页中

EDITED: It's an https page. 编辑:这是一个https页面。 I can get the contents of a folder in an http page, but I get an '403 - Forbidden: Access is denied.' 我可以在http页面中获得文件夹的内容,但得到的是“ 403-禁止访问被拒绝”。 error for the folder in an https page. https页面中的文件夹错误。 I have access to webserver. 我可以访问网络服务器。 I use ASP.NET and tried to set permissions in web.config on the folder for all users. 我使用ASP.NET,并尝试为所有用户在该文件夹的web.config中设置权限。 I want to get the list from the client side. 我想从客户端获取列表。 The client script is executed through the same-origin policy. 客户端脚本通过同源策略执行。 I use an ASP.NET web page (but I want to get the files through JavaScript/jQuery). 我使用ASP.NET网页(但是我想通过JavaScript / jQuery获取文件)。 I might use web services. 我可能会使用Web服务。

Thanks for the details. 感谢您的详细信息。 Im sorry I cant set up an ASP.Net website right now, but I still have a few questions. 抱歉,我现在无法建立ASP.Net网站,但是我仍然有几个问题。

Is the client script executed through the same-origin policy or do you need to enable CORS / JSONP ? 客户端脚本是否通过同源策略执行,还是需要启用CORS / JSONP? https://docs.microsoft.com/en-us/aspnet/web-api/overview/security/enabling-cross-origin-requests-in-web-api https://docs.microsoft.com/zh-cn/aspnet/web-api/overview/security/enabling-cross-origin-requests-in-web-api

Do you use ASP.Net WebPage, MVC, WebApi, which version or the new ASP.Net Core version? 您是否使用ASP.Net WebPage,MVC,WebApi,哪个版本或新的ASP.Net Core版本?

My recommendation is to build a webservice/API that reads the folder and delivers the list of files: 我的建议是构建一个可读取文件夹并提供文件列表的webservice / API:

  • you can deliver any format you want like a nice JSON, works well with jQuery 您可以提供所需的任何格式,例如不错的JSON,并与jQuery配合使用
  • you don't need to add/manipulate the web.config which is always better 您不需要添加/操作web.config总是更好
  • you will be able to cache the response and avoiding to much disc access. 您将能够缓存响应并避免大量的光盘访问。 Therefore you need to watch the folder for changes and update the cache 因此,您需要查看文件夹中的更改并更新缓存。
  • if you want to move/split the folder, moving to a db, anything you might need later, its still gonna work: the url will remain the same 如果您想移动/拆分文件夹,移动到数据库,以后可能需要做的任何事情,它仍然可以工作:URL将保持不变

With WebApi this might helps: https://stackoverflow.com/a/25986573/117314 借助WebApi,这可能会有所帮助: https ://stackoverflow.com/a/25986573/117314

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

相关问题 如何使用 Jquery/Javascript 将我的一个文件夹中的所有图像加载到我的网页中 - How to load all the images from one of my folder into my web page, using Jquery/Javascript 如何在javascript + html中的文件夹中获取所有文件名和子文件夹名? - how to get all files names and sub folder names in a folder in javascript+html? 如何使用JavaScript将jQuery添加到我的网页? - How can I add jQuery to my web page using Javascript? 使用JavaScript将图片名称从文件夹加载到数组 - Using javascript, load images names from a folder to an array 如何使用javascript或jquery在页面加载时打印pdf文件 - How to print a pdf file on page load, using javascript or jquery 如何使用javascript / jquery将xml文件加载到jsp / html页面 - how to load xml file to jsp/html page using javascript/jquery 如何使用JavaScript或jQuery从特定目录中检索文件名? - How to retrieve file names from a specific directory using JavaScript or jQuery? 有没有办法只使用Javascript从文件夹中返回所有图像文件名列表? - Is there a way to return a list of all the image file names from a folder using only Javascript? 如何使用javascript加载我页面上的所有元素? - how to load all elements on my page with javascript? 使用.get()检索服务器上文件夹中所有文件名的数组 - Using .get() to retrieve an array of all file names in a folder on my server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM