Функция ниже сделает Ajax-вызов для загрузки данных из базы данных MySQL:
function displayAll() {
clearInterval ( stopCompoundingInt ); //stop current Interval
sendAjax('search', 'q', function(responseText){
$("#txtResp").html(responseText);
stopCompoundingInt = setInterval ( function(){ // start a new interval with below conditions:
sendAjax('search', 'q', function(responseText){
$("#txtResp").html(responseText);
});
}, 5000 );
})
}
Вот одно из мест, где оно применяется:
var eInput = "";
stopCompoundingInt = 0;
$('#searchbar').live('keyup',function() {
eInput = $(this).val();
if (eInput.length > 0) {
clearInterval ( stopCompoundingInt );
$('#display_all').hide();
sendAjax('search', eInput, function(responseText){
$("#txtResp").html(responseText);
stopCompoundingInt = setInterval ( function(){
sendAjax('search', eInput, function(responseText){
$("#txtResp").html(responseText);
});
}, 5000 );
})
} else {
displayAll(); // run the above function to show all events
}
});
Предполагается, что функция запускается с интервалом в 5 секунд, если в текстовом поле нет текста с идентификатором = "searchbar"
Есть ли у кого-нибудь какие-либо предложения, которые улучшат производительность этой функции?
Большое спасибо,
Тейлор