-1
我試圖將查詢輸出到JavaScript對象中。我在網上搜索了關於如何完成這件事的文章,但我似乎無法理解。 查詢在下面的php代碼中完成。我的問題是我如何輸出一個PHP變量的結果到一個JavaScript對象?有人能指導我如何完成這項工作嗎?請注意我對如何去做這件事有一絲知識,所以請和我一起裸照。將PHP加載到Javascript中
<?php
$connect = pg_connect("host=127.0.0.1 dbname=bis user=bran6 password=cbrat") or die("Could not connect: ");
$result = pg_query($connect,"SELECT distinct thestartgeom FROM bike");
if (!$result)
{
echo "no results ";
}
$data[];
while($row = pg_fetch_array($result))
{
$data[] = $row['the_start'];
}
pg_close($connect);
?>
<html>
<head>
<title>Simple Map</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
html, body, #map-canvas {
margin: 0;
padding: 0;
height: 100%;
}
</style>
var ar =<?php echo json_encode($data)?>;
writeln(ar);
</script>
</head>
<body>
</body>
</html>
當我看在控制檯我收到一個未捕獲的SyntaxError:意外的標記<。
'ajax'我的朋友''ajax'。這就是你需要的一切。 – Nytrix
呈現的代碼是什麼? (從瀏覽器查看源代碼) –
與此處發佈的代碼相同。 –