使用jQuery獲取示例http獲取請求從數據庫獲取json。當我執行get請求時,我從DB獲得了json數組。另外我試圖在HTML頁面中顯示json,所以我用jquery $(newData).html(data)
來顯示json。但我無法看到HTML頁面中的json,<span>
標籤中的單詞也消失了,我覺得它試圖顯示整個json,但它在頁面上看不到,所以需要幫助顯示json數據。頁。如何使用jQuery顯示從數據庫獲取到HTML頁面
<!DOCTYPE html>
<html>
<head>
<title>Http Get Method</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$.get("http://citibikenyc.com/stations/json",function(data, status){
$("#newData").html(data);
});
});
});
</script>
<!-- <link rel="stylesheet" type="text/css" href="getMethod.css"/> -->
</head>
<body>
<button> Get </button>
<span id="newData">
DISPLAY THE RESULT
</span>
</body>
</html>
請創建一個工作示例,以便我相應地爲您提供幫助。 –