javascript - Normal redirect or preload -
so on net i've come across several ways preload / redirect webpage.
now's question proper way handle redirect preload (load next page async while still showing current page)
$.get("page.php", function (data) { document.open(); document.write(data); document.close(); window.history.pushstate("title", "title", "/page.php"); $.cache = {}; }, "html");
or should better stay regular redirect?
window.location = "page.php";
the next page contains fullscreen video , soundtrack (audio)
thanks.
you can use ajax load next page asynchronous. here example of simple ajax request using get method, written in javascript.
ajax stands asynchronous javascript , xml, , xmlhttprequest object behave ajax, async parameter of open() method has set true:
xhr.open('get', 'send-ajax-data.php', true);
get-ajax-data.js:
// client-side script. // initialize ajax request. var xhr = new xmlhttprequest(); xhr.open('get', 'send-ajax-data.php', true); // `true` makes request asynchronous // track state changes of request. xhr.onreadystatechange = function () { var done = 4; // readystate 4 means request done. var ok = 200; // status 200 successful return. if (xhr.readystate === done) { if (xhr.status === ok) { alert(xhr.responsetext); // 'this returned text.' } else { alert('error: ' + xhr.status); // error occurred during request. } } }; // send request send-ajax-data.php xhr.send(null);
and @ end can use below codes reload or redirect page data:
document.getelementbyid("mydiv").innerhtml = xhr.responsetext;
Comments
Post a Comment