A
A
Andrew Kolomiets2021-10-06 11:20:17
AJAX
Andrew Kolomiets, 2021-10-06 11:20:17

How to make the same transition on navigation links, like YouTube or VKontakte?

I've seen transitions done but not much different

let showContent = link => {  
            let [cont, http] = [document.getElementById('contentBody'), createRequestObject()];  
            if(http){  
                http.open('get', link);  
                http.onreadystatechange = () => {  
                    http.readyState == 4 && (cont.innerHTML = http.responseText);  
                }  
                http.send(null);      
            }  
            else document.location = link;  
            }  

        // создание ajax объекта  
        const createRequestObject = () =>{  
            try { return new XMLHttpRequest() }  
            catch(e){  
                try { return new ActiveXObject('Msxml2.XMLHTTP') }  
                catch(e){  
                    try { return new ActiveXObject('Microsoft.XMLHTTP') }  
                    catch(e) { return null; }  
                }  
            }  
        }

<form>  
        <input onclick="showContent('page1.html')" type="button" value="Страница 1">  
        <input onclick="showContent('page2.html')" type="button" value="Страница 2">  
</form>


I posted it on index.html, the pages are rendered there, the location does not change. I need the location to change to the appropriate one (page1.html, for example).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nadim Zakirov, 2021-10-06
@zkrvndm

Use jQuery.ajax() to load pages without refresh.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question