Answer the question
In order to leave comments, you need to log in
How to properly organize dynamic block updates?
Hello, please do not throw stones at the question, I will try to express it as clearly as possible.
We are working on a site in which one of the pages can be called SPA with a stretch (when you click on a certain menu item, the content of a certain block is updated, the page is not reloaded). The function responsible for this works as follows:
function myrender(object, selector, modal){
//$( selector).load('/public_html/'+object+'.html');
$.ajax({
url: '/myrender',
type: "post",
data: 'load='+ object +'&modal='+ modal,
beforeSend: function(){
},
success: function(data){
if(data.length > 100){/*Проверяя длину ответа, мы можем примерно понять пришло сообщение джсон ,или же хтмл*/
$(selector).html(data);
//alert(data.length);
}
else {
data = JSON.parse(data);
alert(data.msg);
}
}
});
}
/*
Полный код приводить думаю нет смысла, так как тут только
всякие проверки и валидации и запросы к БД
*/
$app->render('/public_html/'$_POST['load'].'html',['data'=> $data]/*данные к отправке*/;
Answer the question
In order to leave comments, you need to log in
1. Check why the server is taking so long to respond. What's in beforeSend, maybe there's a timeout or a hell of a function to calculate the flight path of the cuckoo's nest.
2. Do a timeout, after which the response no longer matters and the block will not be updated or a regular get will be performed.
3. The bike that you invent has already been invented. It's called pjax: https://github.com/defunkt/jquery-pjax
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question