2016-07-11 13 views
0

入力ドロップダウンの例を変更しようとしていますが、私はdbから抜き出しています。 ここに私のコードです。DropDown PHP jsonの値を使用して入力し、JQueryを使用して入力します。

<script src="//code.jquery.com/jquery-1.10.2.js"></script> 
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> 
<script> 
var dropoffsuburbcode2 = []; 
    getEBRates(); 
function getEBRates() 
{ 
    if (window.XMLHttpRequest) {xmlhttp3 = new XMLHttpRequest();} 
     else {xmlhttp3 = new ActiveXObject("Microsoft.XMLHTTP");} 

xmlhttp3.onreadystatechange = function() 
{ 
     if (xmlhttp3.readyState == 4 && xmlhttp3.status == 200) 
{ 
      dropoffsuburbcode = xmlhttp3.responseText; 
      setcode(dropoffsuburbcode); 
}  
}; 
    xmlhttp3.open("GET","php/Rates.php",true); 
    xmlhttp3.send(); 
} 

function setcode(suburb){ 
dropoffsuburbcode2 = suburb; 
dropoffsuburbcode2 = dropoffsuburbcode2.replace(/['"\]\[]/g, ''); 

alert(dropoffsuburbcode2); 

このアラートは、このコードは、唯一availableTagsで動作しますが、私は以下のように行うdropoffsuburbcode2使用しようとすると、私は何を取得POCODE1SUBURB1、POCODE1SUBURB2

を返します。

var availableTags = [ 
"ActionScript", 
    "AppleScript", 
    "Asp", 
    "BASIC", 
    "C", 
    "C++", 
    "Clojure", 
    "COBOL" ]; 
$("#tags").autocomplete({ 
    source: dropoffsuburbcode2 
}); 
}; 
</script> 
</head> 
<body> 

<div class="ui-widget"> 
<label for="tags">Tags: </label> 
<input id="tags"> 
</div> 

以下のPHPファイルのコード(Rates.php)私はdropoffsuburbcode2は、文字列の配列ではないかもしれないので、それはだと思う任意のヘルプ

答えて

0

ため

$strSQL2 = "SELECT * FROM db_ebrates"; 
$EventList_rs2 = mysql_query($strSQL2); 
while($row = mysql_fetch_array($EventList_rs2)) { 
$ebsuburbarrray[] = "".$row['ebratesPostcode']. "" .$row['ebratesSuburb']. ""; 
} 
echo json_encode($ebsuburbarrray); 

感謝。しかし、私はAjaxを使用し、jsonから配列を移入することをお勧めします。

関連する問題