Q: Refresh Page after AJAX - sometimes fails I'm using this to refresh/reload a page once ajax completes.
$(".method").click( function() {
    if (confirm('Do  : ' + $(this).attr('method') + ' ?')) {
        $.ajax({ url : 'go.php?method=' + $(this).attr('method'),
        success: function(){
           setTimeout(function(){
           window.location = "?method=view";
            }, 100);
        }
   });
}
    return false;
});

Some times it works and the page refreshes, other times the ajax part works but the page doesn't refresh.
go.php is always called and runs correctly.
Any to get it to work all the time ?
Thanks

A: I believe an error is occurring during the ajax process.  Go.php will always be called but the response back to the browser can obviously vary.  You can specify an ERROR function and do the same thing as success, but you probably want to display an error message instead.
$(".method").click( function() {
    if (confirm('Do  : ' + $(this).attr('method') + ' ?')) {
        $.ajax({ url : 'go.php?method=' + $(this).attr('method'),
            success: function(){
                setTimeout(function(){
                    window.location = "?method=view";
                }, 100);
            },
            error: function(){
                setTimeout(function(){
                    window.location = "?method=view";
                }, 100);
            }
        });
    }
    return false;
});

Alternatively if you don't care about success or error, you can use complete which will do the same for both.
$(".method").click( function() {
    if (confirm('Do  : ' + $(this).attr('method') + ' ?')) {
        $.ajax({ url : 'go.php?method=' + $(this).attr('method'),
            complete: function(){
                setTimeout(function(){
                    window.location = "?method=view";
                }, 100);
            }
        });
    }
    return false;
});


A: try to use this code:
$(".method").click( function() {
    if (confirm('Do  : ' + $(this).attr('method') + ' ?')) {
        $.ajax({
        url : 'go.php?method=' + $(this).attr('method'),
        success: function(){
        },
        complete: function() {
           setTimeout(function(){
           window.location.href = "?method=view";
           }, 100);

        }
   });
}
    return false;
});

reference: https://api.jquery.com/jQuery.ajax/ (complete section)
