我正在尝试将响应数据包装在li
元素中,但它不起作用。但是,如果我没有li
并且只是正常document.getElementbyId....
那么相同的脚本,那么它的工作正常。包装它只是在浏览器中没有显示任何内容。
没有LI
for (x in arrjson) {
longLink = "http://app.******.com/api/refer/"+arrjson[x];
customParam = x;
client.shorten(longLink, {"custom_hash": customParam}).then(function (result) {
console.log(result);
if(result.urls[0].error.details != "That custom hash is already in use") {
document.getElementById("demo").innerHTML += result.urls[0].short_url +"<br>";
} else {
document.getElementById("demo").innerHTML += result.urls[0].error.details +"<br>";
}
});
}
脚本工作但输出未显示。
text
变量在函数外部定义。
text = "<ol>";
for (x in arrjson) {
longLink = "http://app.*****.com/api/refer/"+arrjson[x];
customParam = x;
client.shorten(longLink, {"custom_hash": customParam}).then(function (result) {
console.log(result);
if(result.urls[0].error.details != "That custom hash is already in use") {
text += "<li>"+result.urls[0].short_url +"</li>";
} else {
text += "<li>"+result.urls[0].error.details +"</li>";
}
});
}
text += "</ol>"
document.getElementById("demo").innerHTML += text;
text
变量只返回<ol></ol>
。但是,console.log在两种情况下都返回肯定的结果。