使用jQuery访问本地文件 [英] Accessing Local Files with jQuery

查看:910
本文介绍了使用jQuery访问本地文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我相信这个问题已经以几种不同的形式提出,但是我已经读了很多不同的回答.

I believe that this question has been asked in a few different forms, but I've read quite a few different responses.

首先,我有一个使用jQuery编写的Web应用程序,该应用程序将使用servlet从JavaScript无法访问的各个位置检索信息(即,提要,来自服务器的图像等).但是,现在,我被告知要取消servlet和应用程序配置类,以使我的这个项目仅包含HTML,CSS和JavaScript/jQuery.我需要从计算机上的本地文件中检索图像,而不是将图像从服务器中拉出.我知道允许这样做似乎是很糟糕的设计,但这是我被要求做的事情.无论如何,我真正需要做的是计算目录中图像文件的数量,然后自己编译文件名数组.使用servlet时,我可以在Java中做到这一点,但是如果没有它们,我不确定如何甚至可以做到这一点.

At first, I had a web-application written with mostly jQuery that would make use of servlets to retrieve information from various locations JavaScript could not access (ie. Feeds, images from a server, etc.). Now, however, I've been told to do away with the servlets and application configuration classes so that this project of mine contains only HTML, CSS, and JavaScript/jQuery. Rather than pulling the images off of the server, I need to retrieve them from a local file on the computer. I know that allowing this might seem like terrible design, but it's what I've been asked to do. At any rate, what I really need to do is count the number of image files in a directory and then perhaps compile an array of the filenames themselves. I could do this fine in Java when using the servlets, but without them, I'm not sure how or even if this can be done.

我基本上是在尝试使用jQuery Cycle插件像幻灯片一样循环浏览这些图像.我通过使用基于当前图像数量的循环将这些图像注入(或$(#div").append())到div中.

I'm basically trying to use the jQuery Cycle plug-in to cycle through these images like a slideshow. I inject (or $("#div").append()) these images into the div by using a loop based on the number of images present.

那么,有没有一种方法可以通过使用JavaScript,HTML,jQuery插件等来实现?我现在想避免使用PHP和Java ...

So, is there a way I can do this with using JavaScript, HTML, jQuery plug-in, etc? I'd like to avoid using PHP and Java at this point...

推荐答案

您不能只使用JavaScript来读取目录;但是,似乎有一种方法可以使用 http://www.irt来利用"浏览器的功能.org/articles/js014/.它可能并不漂亮,但是该演示适用于我最新的Chrome和IE7-9.我敢肯定,如果您想改进某些技术,可以使用更干净的代码.

You can't just read a directory with JavaScript; however, there appears to be a way to "exploit" how browsers function using http://www.irt.org/articles/js014/. It may not be pretty, but the demo works in the latest Chrome and IE7-9 for me. I'm sure some of the techniques could be updated to use cleaner code if you'd like to improve upon it.

您可以在文件夹中的Javascript读取文件中找到另一种可以使用的技术

它肯定看起来是一种更清洁的解决方案.我建议您提取主体内容以注入到隐藏的div中,或使用可读取iframe的路径.

It definitely looks to be a cleaner solution. What I'd recommend is extracting the body contents to inject into a hidden div or using the path for an iframe that you can read from.

这篇关于使用jQuery访问本地文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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