Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript reload() not working

I searched everywhere here to see since so many people ask this question, but no matter what, I keep getting undefined..

function remove_item(itemid) {
    var window = top.location;
    var host = window.host;

    $.ajax({
        url: "http://"+host+"/backend/remove_lockbox.php?id="+itemid,
        success: function() {
            $(document).ajaxStop(function(){
                window.top.location.reload();
            });
        }
    });
}

That is my code. I tried window.location.reload, host.location.reload... I tried everything and I keep getting undefined... The parent of location is always undefined whether it's window, host, window.top, ANYTHING. Can someone PLEASE help me?

like image 676
Peanut Avatar asked May 25 '12 03:05

Peanut


1 Answers

So you are doing

 var window = top.location;

and than you do

 window.top.location.reload();

So you are actually saying

top.location.top.location.reload();

Why would you use a variable named window when that is already defined and has a different meaning? That is bad.

If you are using frames I would expect to see something like

parent.location.reload(true);

or just a plain old window

window.location.reload(true);
like image 103
epascarello Avatar answered Oct 09 '22 01:10

epascarello