What can be the possible issue for 403 error for my ajax code?

I am trying to load images in a folder it is showing 403 forbiden error but i don’t have any permission problems. what can be the issue?

var dir = "img/";
    var fileextension = ".jpg";
    debugger;
    $.ajax({
        url: dir,
        success: function (data) {
            //List all .png file names in the page
            $(data).find("a:contains(" + fileextension + ")").each(function () {
                debugger;
                var filename = this.href.replace(window.location.host, "").replace("http://", "");
                $("body").append("<img src='" + dir + filename + "'>");
            });
        }
    });

It’s not possible to browse or scan a server directory with JS – you can only load specific files. Not sure why you’re getting a 403 though… if you’re trying to load a resource that does not exists (and img/ as such probably doesn’t), you’d get a 404…

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.