1
$(document).ready(function (){

    var names = new Array();

    names[0] = 'jimit';
    names[1] = 'vinod';
    names[2] = 'vineet';

    for( var x in names){
        console.log(names[x]);
    }
    window.reLoad();


});

In the above code I want to wait till my for execution completes and then call window.reLoad();

Thanks

EDIT:

The above code is in callback function of an ajax request will this make a difference??

6
  • why are you overwriting you first array element for two times in a row after its definition? is it intended? Commented Mar 12, 2011 at 7:50
  • OK, you probably expect that you see three log outputs before reLoad() is called? That just doesn't happen because you store into the same array slot three times. If this is not the problem, can you please elaborate? Commented Mar 12, 2011 at 7:51
  • @Lucius $alienhard Sorry i didnt want to add to same array slot edited my question Commented Mar 12, 2011 at 8:00
  • Looks like it is already the way you want it. What is your problem? Commented Mar 12, 2011 at 8:09
  • @Felix the window.reLoad() doesn't wait till "for" loop completes Commented Mar 12, 2011 at 8:15

1 Answer 1

1
$(function (){
var names = new Array();

    names[0] = 'jimit';
    names[1] = 'vinod';
    names[2] = 'vineet';

    for( var x in names){
    console.log(names[x]);
    }

    window.location = location.href;
})

OR

$(function (){
    var names = new Array();

    names[0] = 'jimit';
    names[1] = 'vinod';
    names[2] = 'vineet';

    for( var x in names){
    console.log(names[x]);
    }


    setTimeout( reloadWindow, 2000 );

})

function reloadWindow(){

    window.location = location.href;

}
Sign up to request clarification or add additional context in comments.

2 Comments

your code is working but i have this in a callback function of an ajax request will this make any difference ????
@jimy well, it won't make any difference. just make sure you do your things before you redirect. If on same page, i recommend you to update page (using js) rather then redirect.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.