Read local directory using jquery/javascript ajax not working on server deploy -
hi able read local directory image files using jquery ajax call. when browse application locally working fine per expected. when deploy in server, (tomcat or other server) shows files directory path not found 404.
find code jquery code.
var dir = "images/"; $.ajax({ url : dir, success: function (data) { debugger; var patt1 = /"([^"]*\.(jpe?g|png|gif))"/gi; // extract "*.jpeg" or "*.jpg" or "*.png" or "*.gif" var result = data.match(patt1); result = result.map(function(el) { return el.replace(/"/g, ""); }); // remove double quotes (") surrounding filename+extension // todo: @ regex! var uniquenames = []; // array remove duplicate images $.each(result, function(i, el){ var el_url_encoded = encodeuricomponent(el); // avoid images same name converted url encoded console.log("under analysis: " + el); if($.inarray(el, uniquenames) === -1 && $.inarray(el_url_encoded, uniquenames) === -1){ console.log("adding " + el_url_encoded); uniquenames.push(el_url_encoded); //$("#slider").append( "<img src='" + el_url_encoded +"' alt=''>" ); // finaly add html $("body").append( "<img src='"+ dir + el_url_encoded +"' height=150px width=100px>" ); $("body").append( "<div>'"+ el_url_encoded +"'</div>" ); } else{ console.log(el_url_encoded + " in!"); } }); }, error: function(xhr, textstatus, err) { alert('error: here go...'); alert(textstatus); alert(err); alert("readystate: "+xhr.readystate+"\n xhrstatus: "+xhr.status); alert("responsetext: "+xhr.responsetext); } }); local application output screenshot working fine. 
same code when run using localhost server not working, shows error path not found 404 , goes error block. why not working can me. great appreciate.

Comments
Post a Comment