使用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>
请创建一个工作示例,以便我相应地为您提供帮助。 –