Add a random number parameter when sending the request, so that the browser will re-send the request to the server every time

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>web_GET</title>
 6 </head>
 7 <body>
 8     <button class="btn">发送GET请求</button>
 9     <script src="./jquery.min.js"></script > 
10      < script > 
11          var page = {
 12              init : function (){
 13                  this .bindEvent();
 14              },
 15              bindEvent : function (){
 16                  var _this =  this ;
 17                  $(document).on( ' click ' , ' .btn ' , function (){
 18                      // Generate a 5-digit random number 
19                      var rnd = _this.randomNum(5);
20                     console.log(rnd);
21                     $.ajax({
22                         type     : 'get',
23                         url      : 'http://10.10.0.190:3000/WorkStat/workstat/get_user_latest_work_hist?rnd='+rnd,
24                         dataType : 'json',
25                         data     : {
26                             user_id : 02519
27                         },
 28                          success : function (res){
 29                              console.log(res);
 30                          },
 31                          error : function (err){
 32                              console.log(err);
 33                          }
 34  
35                      })
 36                  })
 37              },
 38              // Generate random number function 
39              randomNum : function (n){
 40                  var randomNum= '';
41                 for(var i=0; i<n; i++){
42                     randomNum += Math.floor(Math.random()*10);
43                 }
44                 return randomNum;
45             }
46         }
47         $(function(){
48             page.init();
49         })
50     </script>
51 </body>
52 </html>

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325848003&siteId=291194637