Javascript 循环发布ajax结果,直到它们全部发布

Javascript 循环发布ajax结果,直到它们全部发布,javascript,jquery,ajax,Javascript,Jquery,Ajax,下面的代码非常适合在我的第一个文件中显示 $.ajax({ url : "http://localhost/website/files/userstuff/files/", asynch : false, cache : false, success: function (data) { $(data).find("a").each(function(i, el) { var val = $(el).attr('href')

下面的代码非常适合在我的第一个文件中显示

$.ajax({
    url : "http://localhost/website/files/userstuff/files/",
    asynch : false,
    cache : false,
    success: function (data) {
        $(data).find("a").each(function(i, el) {
            var val = $(el).attr('href');
            if (val.match(/\.(pdf|doc|docx|txt|html|js|css|rar|7zip)$/)) {
                var fileslocation = ("http://localhost/website/files/userstuff/files/" + val)
                var displayfilestable = ("<table><thead><tr><th>Files</th></tr></table>");
                var adddata = ("<tr><td><a href='"+ fileslocation +"'target='_blank'>"+ val +"</td></tr>");
                $("#filestable").html(displayfilestable)
                $("filestable, table").append(adddata);
                console.log(adddata)
            }
        });
    }
});
$.ajax({
url:“http://localhost/website/files/userstuff/files/",
asynch:false,
cache:false,
成功:功能(数据){
$(数据)。查找(“a”)。每个(函数(i,el){
var val=$(el.attr('href');
if(val.match(/\(pdf | doc | docx | txt | html | js | css | rar | 7zip)$/){
var fileslocation=(“http://localhost/website/files/userstuff/files/“+val)
var displayfilestable=(“文件”);

var adddata=(“

您的代码运行良好。问题是,在该循环中(每个循环)您都保持重新创建表。这就是为什么它只显示1个数据。请根据您的代码检查我的示例

HTML




JAVASCRIPT

var displayfilestable = ("<table><thead><tr><th>Files</th></tr></table>");
$("#filestable").html(displayfilestable);
$("DIV").find("a").each(function(i, el) { // this is your data
    var val = $(el).attr('href');
    if (val.match(/\.(pdf|doc|docx|txt|html|js|css|rar|7zip)$/)) {
        var fileslocation = ("http://localhost/website/files/userstuff/files/" + val)
        var adddata = ("<tr><td><a href='"+ fileslocation +"'target='_blank'>"+ val +"</td></tr>");
        $("filestable, table").append(adddata);
                console.log(adddata)
    }
 });
var displayfilestable=(“文件”);
$(“#filestable”).html(displayfilestable);
$(“DIV”).find(“a”).each(函数(i,el){//这是您的数据
var val=$(el.attr('href');
if(val.match(/\(pdf | doc | docx | txt | html | js | css | rar | 7zip)$/){
var fileslocation=(“http://localhost/website/files/userstuff/files/“+val)

var adddata=(“

你能发布你的响应数据吗?这意味着你的服务器正在暴露目录中的文件,这是非常不安全的。你应该在服务器配置中修复这一问题,并使用服务器端编程语言来读取directorieshi charlietfl该网站目前没有(我认为永远不会)使用服务器。这是一个为朋友创建的客户端网站,它只通过localhost运行,因此ajax调用work@Kalaiselvan a我包含了一个指向显示响应数据的图像的链接
var displayfilestable = ("<table><thead><tr><th>Files</th></tr></table>");
$("#filestable").html(displayfilestable);
$("DIV").find("a").each(function(i, el) { // this is your data
    var val = $(el).attr('href');
    if (val.match(/\.(pdf|doc|docx|txt|html|js|css|rar|7zip)$/)) {
        var fileslocation = ("http://localhost/website/files/userstuff/files/" + val)
        var adddata = ("<tr><td><a href='"+ fileslocation +"'target='_blank'>"+ val +"</td></tr>");
        $("filestable, table").append(adddata);
                console.log(adddata)
    }
 });