我试图在按钮单击时在输入复选框标记中显示 Json 响应。但我做不到。
谁能指导我怎么做。
下面是代码 -
<!DOCTYPE html>
<html>
<body>
<script
src="https://code.jquery.com/jquery-3.1.1.min.js"
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
crossorigin="anonymous"></script>
<label><input type="checkbox" name="test_name" value=""></label>
<button type="button" onclick="loadDoc()">Change Content</button>
<script>
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementsByName('test_name').innerHTML = JSON.stringify(this.responseText,undefined, 2).replace(/\\n/g, "").replace(/\\r/g, "")
.replace(/\\/g, "")
.replace(/^"/, "")
.replace(/"$/, "");
var jsonobj = JSON.parse(document.getElementsByName('test_name').innerHTML);
for ( var i=0;i<jsonobj.length; i++)
{
console.log(jsonobj[i].Newsletter_Name);
var label = document.getElementsByName('test_name');
console.log(label);
label.value= jsonobj[i].Newsletter_Name;
};
}
};
xhttp.open("GET", "https://members.s7.exacttarget.com/Pages/Page.aspx?QS=38dfbe491fab00ea764e20685ddf905a854eb2c63c649afb00651f16b30a4189&brand_code=PE", true);
xhttp.send();
}
</script>
</body>
</html>
Json Return - 会有很多数据。但我展示的很少。
[{
"Test_Name": "FOOD",
"Brand": "Test"
},
{
"Test_Name": "HOME",
"Brand": "Test"
}]