ストリート名、郵便番号などの位置情報を保持するJSONオブジェクトからデータを取得しようとしていますが、divに入れようとしても何も取得されません。誰かがこれでどこが間違っているのかわかりますか?
これは、データをリクエストして取得するための私のajaxコードです
var criterion = document.getElementById("address").value;
$.ajax({
url: 'process.php',
type: 'GET',
data: 'address='+ criterion,
success: function(data)
{
$('#txtHint').html(data);
$.each(data, function(i,value)
{
var str = "Postcode: ";
str += value.postcode;
$('#txtHint').html(str);
});
//alert("Postcode: " + data.postcode);
},
error: function(e)
{
//called when there is an error
console.log(e.message);
alert("error");
}
});
これをブラウザで実行すると、「郵便番号:未定義」とだけ表示されます。
これは、データベースからデータを選択するためのphpコードです。
$sql="SELECT * FROM carparktest WHERE postcode LIKE '".$search."%'";
$result = mysql_query($sql);
while($r = mysql_fetch_assoc($result)) $rows[] = $r;
echo json_encode($rows), "\n"; //Puts each row onto a new line in the json data