Json对象显示在html中
Json object display in html
嘿,伙计们,我是新的json语法,我有一个问题。我做了一个函数,从远程服务器获取json中的数据,如下所示:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery-3.1.0.min.js"></script>
<script type="text/javascript">
function getStates(value) {
var data = {
q: value
}
$.ajax({
url: 'https://something.hr/api/search',
method: 'GET',
headers: {'Accept': 'application/json'},
data: data
}).done(function(data) {
//do something with data I returned to you
console.log("success")
console.log(data)
}).fail(function(data) {
//doSomethingWith the data I returned to you
console.log("fail")
console.log(data)
});
};
</script>
</head>
<body>
<input type="text" onkeyup="getStates(this.value)" >
<br>
<script>
</script>
</body>
</html>
我的问题是我知道如何在控制台日志中获取对象,但我希望在html中获得该对象,就像在一些框中一样,然后单击它并打开他的数据(名称,id,地址等)
var httpManager = (function() {
var getData = function(value) {
$.ajax({
url: 'https://api.github.com/users/zixxtrth',
method: 'GET'
}).done(function(data) {
//do something with data I returned to you
jQuery('#avatar').attr('src', data.avatar_url);
jQuery('#name').html(data.name);
jQuery('#username').html(data.login);
}).fail(function(data) {
//doSomethingWith the data I returned to you
alert('No Data');
});
};
return {
getData: getData()
}
})();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<img src='' id='avatar' width='200' height='200' />
<h1 id='name'></h1>
<h2 id='username'></h2>
相关文章:
- 谷歌地图不是以HTML显示,而是在JS Fiddle上工作
- 使用鼠标悬停JavaScript/HTML显示文本
- 用javascript在html显示列表中显示新成员
- 尊重“; 〃;从HTML显示中的API响应返回的换行符(和特殊字符)
- HTML 显示/隐藏元素 JS 不起作用
- 从一个文本框执行代码,并在另一个文本框中以 HTML 显示输出
- 使用javascript for html显示特定时区的日期和时间
- 如何将一个元素的外部HTML显示为另一个元素的内容
- 将SQL BIT转换为JSON,直到jQuery,最后以HTML显示
- 使用 Javascript 迭代以 HTML 显示多个图像
- 文本(输入)字段中的 HTML 显示结果
- PHP - 作曲家自动加载器导致 html 显示在浏览器中
- 将HTML文件中的表单提交到PHP文件,并以相同的HTML显示结果
- 如何使 HTML/Javascript 从 PHP 脚本接收数据并以 HTML 显示
- 显示一个图像,然后使用 HTML 显示另一个图像
- input type=“password” 在 IE 11 上使用 HTML 5 显示文本
- 使用 JSON 从 PHP 返回数组并以 HTML 显示内容的适当方法
- Jquery对话框IE9内容未使用html显示
- HTML显示在“;查看源“;与Firebug中显示的HTML不同
- 使用jQuery.HTML()插入时HTML显示不正确