English 中文(简体)
Java Script Script Script Script 素
原标题:JavaScript for loop with innerHTML not updating during loop execution

I m 通过一个阵列,在每一处 lo期间,Im通过亚x指一种ur。 我也希望更新一个内部的超文本,以便显示它能够随时向用户通报正在处理该排他性的问题。 然而,在文字完稿时,只显示最新情况。

我怎么能够在我的休息时间表明这一通知?

I m also using the query ajax setting async: false . I don t want to hammer my server with processing all of the ajax requests at once, as they are encoding video files which is CPU intensive. I don t really want to lock the browser up waiting for synchronous requests to complete either.

是否有更好的办法这样做?

我的最终目标是依次执行我的组合。 每一套录像带的网址,同时向用户展示当前状况指标,同时不把浏览器锁在这一过程之中。 感谢你们的帮助!

这里的《法典》:

www.un.org/Depts/DGACM/index_spanish.htm

// process the loop of videos to be combined
    var status = document.getElementById( currentStatus );
    for (i=0; i< count; i++) {

        // change the display

        var fields = videos[i].split(":", 2);

        current = i +1;

        currentStatus.innerHTML = "<b>Multi-part Videos:</b>&nbsp;&nbsp;&nbsp; <h3 class= status >Currently Updating Bout #" + fields[1] + " (" + current + " of " + count + " videos)</h3>";



        // run the combine 
        var dataString =  videoId= + fields[0]; 



        $.ajax({  
            type: "POST",  
            url: "combine.php",  
            data: dataString,  
            success: function(txt) {


                //deselect the checkbox

                document.combine.video[selected[i]].checked = false;
            },
            async: false 
        }); 

最佳回答

如果你想要在把一对一对一字确定为事实时加以更新,则下一次请求可以成功执行。 更新地位法也应属于这一职能。

function ajaxRequest(i){

        // other processing
        .............

        $.ajax({  
            type: "POST",  
            url: "combine.php",  
            data: dataString,  
            success: function(txt) {

                //deselect the checkbox
                document.combine.video[selected[i]].checked = false;

                // update status
                currentStatus.innerHTML = .....
                // make next request
                if(i<lastOne){
                     ajaxRequest(i+1);
                }
            },
            async: true
        }); 
}
问题回答

async: false will hang the entire browser until the ajax request completes. That is why you don t see the page update on each loop iteration.

同步的亚克斯请求通常会为可怕的未爆炸物质(如:you)提出,如冻结不重复的网页? 自您使用j Query以来,。 递延目标APIC/a”使这一点变得容易。

正如其他人已经提到的那样,你的问题之所以出现,是因为贾瓦文只读一读了——虽然唯一的一份联合材料正等待你提出回去的要求,但不允许它更新联合调查。

You can get around this by changing the request to async, and using the callback to trigger the request for the next object:

// trigger the loop of videos to be combined
var status = document.getElementById( currentStatus );
processVideo( 0 );

function processVideo( index ) {
    var fields = videos[index].split(":", 2);

    currentStatus.innerHTML = "<b>Multi-part Videos:</b>&nbsp;&nbsp;&nbsp; <h3 class= status >Currently Updating Bout #" + fields[1] + " (" + current + " of " + count + " videos)</h3>";

    // run the combine 
    var dataString =  videoId= + fields[0]; 

    $.ajax({  
        type: "POST",  
        url: "combine.php",  
        data: dataString,  
        success: function() {
           processResponse( index);
        },
        async: true
    });
}

function processResponse( index ) {
   // this method is called each time the ajax request finishes
   if (index++ < count) {
      //deselect the checkbox
      document.combine.video[selected[index]].checked = false;

      processVideo( index );
   }
}




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签