我敢肯定我的编码有一百万个问题......
然而,除了自动完成之外,一切正常。
我似乎无法从我的 searchResults 函数返回值。
我想返回字符串。
现在
alert("t: " + availableTags);
工作但
alert("x: " + availableTags);
才不是
返回行都不返回值。
我究竟做错了什么?
$(function(){
//$("#searchButton").click(function(){
//$("input").keyup(function(e){
var availableCompanies = searchResults('CompanyName',false);
var availableLocations = searchResults('Location',false);
$("input[id^='CompanyName']").keyup(function(){
//alert("CN");
searchResults('CompanyName',true);
});//$("input[id=CompanyName]").keyup(function(e){
$("input[id^='Location']").keyup(function(){
searchResults('Location',true);
});
$("input[id^='serving']").keyup(function(){
searchResults('serving',true);
});
$( "#CompanyName" ).autocomplete({
source: availableCompanies
});
$( "#Location" ).autocomplete({
source: availableLocations
});
alert(availableCompanies);
})//$(function(){})
function searchResults(which,populate,availableTags){
//clear search results
$("#searchResults").text("");
//clear available tags
//jqxAlert.alert(which);
//var sSearch = $("#search").val();
var sSearch = $("input[id='"+which+"']").val();
var url = "search.asp?" + which + "=" + sSearch;
//alert(url);
var availableTags = "";
$.get(url, function(data){
//$('#searchResults').html(data);
var uid =""
var company = "";
var location = "";
var phone1 = "";
var phone2 = "";
var phone3 = "";
var html = "";
var sql = "";
var i = 1;
if ($('company',data).text() == ""){
$("#searchResults").html("<tr><td>Sorry, there are no results.</td></tr>");
};
$.each($('company',data),function(index, el) {
uid = $(this).find('uid').text();
companyName = $(this).find('CompanyName').text();
location = $(this).find('location').text();
//phone1 = $(this).find('phone1').text();
//phone2 = $(this).find('phone2').text();
//phone3 = $(this).find('phone3').text();
//serving = $(this).find('serving').text();
//sql = "<br />" + $(this).find('sql').text() + "<br />";
//alert(which == "CompanyName");
if (which == "CompanyName"){
//availableTags = availableTags + companyName;
if (availableTags.indexOf(companyName) < 0){
if (availableTags == "") {
availableTags = companyName;
}else{
availableTags = availableTags + "," + companyName;
}
}
}
if (which == "Location"){
if (availableTags.indexOf(Location) < 0){
if (availableTags == "") {
availableTags = Location;
}else{
availableTags = availableTags + "," + Location;
}
}
}
if (sSearch != ""){
if (i % 2 == 0){
html = '<div id="c_' + uid + '" class="bgGrey">';
}else{
html = '<div id="c_' + uid + '" class="bgWhite">';
}
html = html + "<tr>";
html = html + "<td><b>←</b>" + companyName + " (" + location + ")</td>";
//html = html + company + " " + location ;
html = html + "</tr>";
html = html + "</div>";
//$("#searchResults").append(i + ' ' +x + ' ' + y + ' ' + sql + html);
$("#searchResults").append(html);
}
i++;
}); //$.each($('company',data),function(index, el) {
if (populate){
PopulateFields();
}else{
alert("t: " + availableTags);
return "test";
}
}).error(function() {
$("#searchResults").html("<tr><td>Results could not be retrieved. Alert T. McDermott</td></tr>");
}); //$.get(url, function(data){
alert("x: " + availableTags);
return availableTags;
}