Javascript reload () not working

I searched everywhere here to see, as many people ask this question, but no matter, 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(); }); } }); } 

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

+4
source share
2 answers

So you do

  var window = top.location; 

and what are you

  window.top.location.reload(); 

So you really say

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

Why are you using the named window variable if it is already defined and has a different value? This is bad.

If you use frames, I expect to see something like

 parent.location.reload(true); 

or just an ordinary old window

 window.location.reload(true); 
+9
source

try it this way, its work works fine in chrome, as I know that this should work well in all modern browsers.

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

Here is a working example of window.location , window.location.host and window.location.reload .

http://jsbin.com/apemen/3

+1
source

Source: https://habr.com/ru/post/1414294/


All Articles