私のコーディングには何百万もの問題があると確信しています...
ただし、オートコンプリート以外はすべて機能します。
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;
}