0

While developing a image gallery using javascript,jquery & ajax , the code do not run in loacally(eg:path:"file:///C:/wamp/www/photogallery/index.html") but if run this in localhost as(path:"localhost/photogallery/") it run perfectly and got output.

My officer said that there will be some problem with code. because jquery will run without using the localhost.

Please help me to solve this problem. Please notify the mistakes from me..

code given below.

1) to display all images from a folder (can read all images having different names like 1.jpg,asd.jpg,ertt.jpg)

var dir=album_name;
    var fileextension=".JPG";
    $.ajax({
        url: dir,
        async:false,
        success: function (data) {// function to read image files
            $(data).find("a:contains(" + fileextension + ")").each(function () {
                var filename = this.href.replace(window.location.host, "").replace("http:///photogallery",""); 
                data1[j++]=dir+filename;
            });
        }
    });

2) to count the no of folder in a directory

function countFolder(){
var dir='albums';
var count=12;
alert(dir);
$.ajax({
    url: dir,
    async:false,
    success: function (data) {
        $(data).find("a:contains(" + 'album' + ")").each(function () {// function to read foldera name contains 'album'
            count++;
            //alert(url);
        });
    }
});
return count;

}

Thanks in advance...

value of dir is path to directory having sub folder. for me it is 'albums'

if we run file locally these codes do not working.... if localhost work perfectly..

1st code returns path of image files in a folder 2nd code returns subfolders count.

aju2529
  • 45
  • 7
  • 2
    What is the value of "dir"? – Pete Sep 24 '13 at 17:38
  • 3
    possible duplicate of [Using ajax to access web from local file](http://stackoverflow.com/questions/5933834/using-ajax-to-access-web-from-local-file) – PlantTheIdea Sep 24 '13 at 17:38
  • 3
    Debug this in your browser. (Firebug, Chrome tools, etc.) Is the AJAX call being made? What is the address it's calling? What is the response from that call? – David Sep 24 '13 at 17:38

0 Answers0