Answer the question
In order to leave comments, you need to log in
How to work with ajax correctly?
Friends, there was such a problem .. Let's
start with the structure of the ajax request
$.ajax({
url: window.location.href,
cache: true,
success: function(html){
$("body").html(html);
}
});
<body></body>
entire structure from the container is loaded into the page body ( ) <head></head>
Answer the question
In order to leave comments, you need to log in
Try one of these 2 options.
Option one:
$.ajax({
url: window.location.href,
cache: false,
success: function(html){
var page = document.createElement('page'); // Создаем пустой элемент с тегом page
page.innerHTML = html; // Записываем в него ответ сервера
var body = page.querySelector('body').innerHTML; // Считываем с него содержимое тега body
document.querySelector('body').innerHTML = body; // Записываем спасренный код на страницу
}
});
$.ajax({
url: window.location.href,
cache: false,
success: function(html){
document.write(html); // Перезаписываем текущий документ полностью
document.close(); // Закрываем запись
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question