Use jQuery to refresh the page

------------ Recovery content started ------------

Method 1: Use location.reload ()

The location.reload () method reloads the current web page. This method is similar to the refresh page button on your browser. If you set the parameter of this method to the true parameter, you can force the page to load from the server and ignore the browser cache.

grammar:

location.reload(true)

Example:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">

</head>
  
<body>
    <h3 style="color: green">如何使用jQuery刷新页面?</h3>
    <p>这是一段测试文本!</p>
          输入文本:<input type="text" /><br /><br />
      
    <button type="button">重新加载页面</button>
    <script src="https://code.jquery.com/jquery-3.3.1.min.js"> </script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("button").click(function () {
                location.reload(true);
                alert('Reloading Page');
            });
        });
    </script>
</body>
  
</html>

Method 2: Use history.go (0)

The history.go () method loads a URL from the browser history based on the parameters passed to it. If the passed parameter is "0", the current page will be reloaded.

grammar:

history.go(0);

Example:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">

</head> 
  
<body> 
    <h3 style="color: green">如何使用jQuery刷新页面?</h3> 
    <p>这是一段测试文本!</p> 
          输入文本:<input type="text" /><br /><br />
      
    <button type="button">重新加载页面</button> 
    <script src="https://code.jquery.com/jquery-3.3.1.min.js"> </script> 
    <script type="text/javascript"> 
        $(document).ready(function () { 
            $("button").click(function () { 
                history.go(0); 
            }); 
        }); 
    </script> 
</body> 
  
</html>

  

Guess you like

Origin www.cnblogs.com/gechen/p/12682810.html