我使用JS在我的网页上做一些功能,我有后端函数给我这个JSON
{ "id": 1, "name": "First Like", "description": "Like at least 1 page", "image": "images/badges/FIRST_LIKE"}
所以我学会了如何使用jQuery获取这些属性,我可以得到" name"和"描述"但不知何故,我无法得到"图像"我需要添加到url以调用图像href的atribute。谁能帮我?这是我的JS功能:
jQuery(function($){
$.getJSON('http://eclipsewildflyserver-gobanit.rhcloud.com/something/id=1',
function (data) {
var name=data.name;
var description=data.description;
var image=data.image;
document.getElementById("name").innerHTML = name.toString();
document.getElementById("description").innerHTML=description.toString();
document.getElementById("image").innerHTML=image.toString();
});
});
它没有给我任何错误或什么。只是不会得到"图像"属性附加伤害。
答案 0 :(得分:0)
对于代码
Uncaught ReferenceError: _classCallCheck is not defined
,您需要使用image
属性:
src
你不需要拨打document.getElementById("image").src = image;
功能,它已经toString()
参见工作示例:
String

var data = { "id": 1, "name": "First Like", "description": "Like at least 1 page", "image": "http://cdn.sstatic.net/stackoverflow/company/img/logos/so/so-icon.png?v=c78bd457575a"};
var name=data.name;
var description = data.description;
var image = data.image;
document.getElementById("name").innerHTML = name;
document.getElementById("description").innerHTML = description;
document.getElementById("image").src = image;