mercredi 17 novembre 2021

How to change the web address,at the same time, only refresh a part of page?

I used Ajax to refresh page.but the address has not chenged.

function refresh(page) {
        let xmlhttp;
        if (window.XMLHttpRequest)
        {
            xmlhttp=new XMLHttpRequest();
        }
        else
        {
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function()
        {
            if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
                document.getElementById("test").innerHTML=xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET",page,true);
        xmlhttp.send();
    }

I add this in order to change address

        let newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + '?foo=bar';
        window.history.pushState({path:newurl},'',newurl);

It's can work, but, I cant visit the website using this new url. I want my web site like the Android Guides. when I changed the address. only refresh a part of page.

Please excuse me for my bad english!




Aucun commentaire:

Enregistrer un commentaire