2

I can't find anything at all on the web about what I am trying to achieve. I am simply trying to load a directory with jquery Ajax but it just seems to fail miserably.

The reason I am trying to do this is for a quick way to scroll through files in a directory without using php.

Scenario:

Load the directory, grab the first three files (img files actually), and DISPLAY on the page.


I have tried the following:

$.load("directory"); // This is a generalization of what I've written
$.get("directory"); 

both of these fail, I get an error in my console saying: 404 not found, But the directory does in fact exist.

Is this even possible with ajax?

Andrew
  • 3,393
  • 4
  • 25
  • 43
  • Local directory, or directory on a webserver? Local directory doesn't make sense and it's a security risk. – int21h Jul 26 '14 at 03:24
  • On the server. I have image files in a known directory on the server. – Andrew Jul 26 '14 at 03:24
  • and you're able to browse the directory in a browser? – int21h Jul 26 '14 at 03:25
  • No, I can't view the directory in itself, but I can access files inside the directory. – Andrew Jul 26 '14 at 03:26
  • So, you want to "upload them" to the server when they're already there? Do you really just want to show them in the browser? – TLS Jul 26 '14 at 03:26
  • @TLS No, I want to retrieve them from the server. Like, dynamically update a page with the first three images in the directory. – Andrew Jul 26 '14 at 03:27
  • AJAX is client-side, so it won't be able to directly look at a server folder (unless you can browse to it). You'll need something that runs on the server-side to provide some bits of data to the AJAX. – TLS Jul 26 '14 at 03:28
  • If you can't browse the directory with a browser you can't do it with jQuery. That's essentially what you need unless you know the filenames up front EDIT: Actually that won't work either because you would only be able to retrieve the file contents... – int21h Jul 26 '14 at 03:28
  • Okay, so it's impossible. So there's no answer to this question..? -- that being without using a server side language. – Andrew Jul 26 '14 at 03:30
  • It's possible if you can browse to the directory and then scrape the output to find the file names and such that you want. Without exposing the directory to the browser, it will require server-side stuff. – TLS Jul 26 '14 at 03:33
  • @TLS It's possible if I can browse to the directory? How does a directory become visible? I don't mind it being visible to the browser. – Andrew Jul 26 '14 at 03:35
  • That's a server-side setting. The Web server has to be set to allow directory browsing. It's a completely different question. – TLS Jul 26 '14 at 03:37
  • Okay. I'll ask it then./ Look for it. – Andrew Jul 26 '14 at 03:37

1 Answers1

-1

To get list of files and folders you will need server-side programming so that can't be done using ajax. the web server will redirect your request to index.html|php or return an 4XX error.

Jafar Akhondali
  • 1,552
  • 1
  • 11
  • 25
  • Well, I guess that's a correct answer. Just not a solution I was looking for. Thanks anyways. – Andrew Jul 26 '14 at 03:40