jQuery autocomplete - wait until all documents loaded
I am calling multiple XML documents as source for autocomplete. I want my "loading" message to go awa开发者_开发问答y after all the documents have been loaded. Currently it goes away after the first is loaded.
Thanks
function callAjax(data1, url){
$.ajax({
url: url,
dataType: "xml",
success:
function(xmlResponse) {
totalrec = $("TOTALREC", xmlResponse).text();
endrec = $("ENDREC", xmlResponse).text();
var data = $("ROW", xmlResponse).map(returnResults).get(data);
$.merge(data1, data);
if(endrec<totalrec){
callAjax(data1, url + "&page_no="+ parameter++);
}
$("#_results").removeClass( "ui-autocomplete-loading" ).addClass("idleField");
$("#_results").val( "Search by Application, Keyword, Process or Name" );
$("#_results").attr( "disabled", "" );
$("#_results").autocomplete({
source: data1,
minLength: 0,
selectFirst: true,
select: function(event, ui) {
if(event.keyCode == 13){
window.open(ui.item.url);
$("#_results").blur();
}
}
})
Put the autocomplete code in an else
in the if(endrec<totalrec)
check.
Like so:
function callAjax(data1, url){$.ajax({
url: url,
dataType: "xml",
success:
function(xmlResponse) {
totalrec = $("TOTALREC", xmlResponse).text();
endrec = $("ENDREC", xmlResponse).text();
var data = $("ROW", xmlResponse).map(returnResults).get(data);
$.merge(data1, data);
if(endrec<totalrec){
callAjax(data1, url + "&page_no="+ parameter++);
} else {
$("#_results").removeClass( "ui-autocomplete-loading" ).addClass("idleField");
$("#_results").val( "Search by Application, Keyword, Process or Name" );
$("#_results").attr( "disabled", "" );
$("#_results").autocomplete({
source: data1,
minLength: 0,
selectFirst: true,
select: function(event, ui) {
if(event.keyCode == 13){
window.open(ui.item.url);
$("#_results").blur();
}
}
});
}
}
});
精彩评论