[Ajax] Solve the problem of IE browser cache not updating

illustrate

By xhr.open('GET', 'http://127.0.0.1:8000/ie?t='+Date.now());setting the parameters in the request, you can prevent the IE browser from calling the cache.

Front-end files

<html>
    <head>
        <meta http-equiv="Access-Control-Allow-Origin" content="*" />
    </head>
    <body>
        <button>press</button>
        <div id="content" style="width: 300px;height:200px;border:1px solid;"></div>
    </body>
    <script>
        const btn = document.getElementsByTagName('button')[0];
        const content = document.getElementById('content');
        btn.onclick = function(){
      
      
            const xhr = new XMLHttpRequest();
            xhr.open('GET', 'http://127.0.0.1:8000/ie?t='+Date.now());
            xhr.send('a=200&b=300');//请求体在这里,可以很灵活
            xhr.onreadystatechange = function(){
      
      
                if(xhr.readyState === 4){
      
      
                    if(xhr.status >= 200 && xhr.status < 300){
      
      
                        console.log(xhr.status);
                        console.log(xhr.statusText);
                        console.log(xhr.getAllResponseHeaders());
                        console.log(xhr.response);
                        content.innerHTML = xhr.response;
                   }
                }
            }
        }
    </script>
</html>

backend files

const express = require('express');
const app = express()
app.get('/server', (Request, Response)=>{
    
    
    Response.setHeader('Access-Control-Allow-Origin', '*')
    Response.send('Hello Ajax')
})
app.get('/ie', (Request, Response)=>{
    
    
    Response.setHeader('Access-Control-Allow-Origin', '*')
    Response.send('Hello IE')
})
app.post('/server', (Request, Response)=>{
    
    
    Response.setHeader('Access-Control-Allow-Origin', '*')
    Response.send('Hello Ajax-4')
})
app.listen(8000, ()=>{
    
    
    console.log('8000 running meproject express')
})


Guess you like

Origin blog.csdn.net/m0_50939789/article/details/128482292