又一个jQuery的AJAX调用循环一个没有的网页渲染回采有的、网页、jQuery、AJAX

2023-09-10 16:54:28 作者:素颜男神

我有超过100行的表。

每行包括PDF文件以及它们与最​​后coloumn状态的描述。

状态显示PDF文件是否可读都没有。

在表是在浏览器中加载,我从表中的每一行歌厅每个文件名,并使用Ajax调用处理它。如果文件是可读的,我更新该行为可读的状态字段。 每个pdf文件取30秒到1分钟的处理(这取决于文件的大小)

我不希望使用异步调用并发送所有100的请求,以我的服务器togather。

当我使用异步=假的。它由一个执行每一个Ajax调用一个,那就是我想要做的, 但在同一时间,它阻止用户浏览装载的表。所以换句话说,用户是种坚持,直到所有的Ajax请求的完成。那么他可以向下滚动到阅读器的更多信息。

我想允许用户阅读网页,一边在后台我想执行的又一个Ajax请求一个处理PDF文件,并​​更新其每一行中的地位。

我如何能做到这一点。

  $('table.tableRecods TR')。每个(函数(){

            。fileWithPath = $('#文件路径)文本();
            $此= $(本);
            $ this.find('td.status img.cropStatus')ATTR('的src','的img / loader.gif')。
                $阿贾克斯({
                    网址:jsonCall.php,
                    异步:假的,
                    数据:{文件:逃生(fileWithPath)},
                    成功:功能(数据){

                            如果(data.status =='真'){
                                $ this.find('td.status img.readStatus')ATTR('的src','的img /图标/ read.png')。
                            }否则,如果(data.status =='假'){
                                。$ this.find('td.status img.readStatus)ATTR(SRC,IMG /图标/ __ read.png');

                            }
                    }
                });

    });
 
关于jquery用ajax调用文本 完全跟网上教程一样的写,却总是不对 以下代码主要的列出来求大师

解决方案

使用AJAX的异步。你可以,例如,有所有你要处理的表行的数组,占据第一位落阵列,并开始查询它。把code在启动时最后一个完成了一个查询监听器。

  VAR toRequest =新阵列(测试1,测试2,TEST3);
功能doRequest(指数){
  $阿贾克斯({
    网址:'?jsonCall.php数据='+ toRequest [指数]
    异步:真正的,
    成功:功能(数据){
      //做你想做就去做

      如果(指数+ 1< toRequest.length){
        doRequest(索引+ 1);
      }
    }
  });
}
doRequest(0);
 

I have a table of of more then 100 rows.

each row consist of pdf files and their description with Last coloumn of STATUS.

STATUS SHOWS whether pdf files are readable are not.

Once table is loaded in the browser, I am geting each file name from every row of the table and processing it using ajax call. if file is readable, i update the status field of that row as READABLE. processing of each pdf file take 30sec to 1 minute (depending upon the size of file)

I don't want to use async call and send all of 100's of request to my server togather.

when I use async= false. it execute every ajax call one by one, that is what i want to do, but in the same time it stop user to browse the loaded table. so in other words user is kind of stuck untill all of those ajax requests are done. then he can scroll down to reader further information.

I want to allow user to read the web page while in the background i want to execute ajax requests one after another to process pdf files and update its status in every row.

How can I do that.

$('table.tableRecods tr').each(function(){

            fileWithPath = $('#filePath').text();
            $this = $(this);
            $this.find('td.status img.cropStatus').attr('src', 'img/loader.gif') ;           
                $.ajax({
                    url:'jsonCall.php',
                    async:false,
                    data: {file: escape(fileWithPath)},
                    success: function(data){        

                            if(data.status == 'true') {
                                $this.find('td.status img.readStatus').attr('src', 'img/icons/read.png') ;                                  
                            }else if(data.status == 'false'){
                                $this.find('td.status img.readStatus').attr('src', 'img/icons/__read.png') ;

                            }
                    }
                }); 

    });

解决方案

Use asynchronous ajax. You could, for example, have an array with all the table rows you want to process, take the first one off the array and start a query for it. Put code in the listener that starts the next query when the last one finished.

var toRequest=new Array("test1", "test2", "test3");
function doRequest(index) {
  $.ajax({
    url:'jsonCall.php?data='+toRequest[index],
    async:true,
    success: function(data){        
      //do whatever you want do do

      if (index+1<toRequest.length) {
        doRequest(index+1);
      }
    }
  }); 
}
doRequest(0);