我不知道为什么我无法使用 RequireJS 在 JS 中解析这个 JSON 文件。var settings = require('https://api.jsonbin.io/b/5e9535d3634f8d782606be53');var parsed = JSON.parse(settings);var indexPar = document.createElement('p');window.onload = testJSON();function testJSON() { indexPar.innerHTML = "Full name is " + parsed.fname + " " + parsed.lname + "\nExpiration Date is " + parsed.expdate + "\nCredit Card # is " + parsed.creditcardnumber + "\nCVV is " + parsed.cvv;}<script type="text/javascript" src="https://requirejs.org/docs/release/2.3.6/r.js"></script>据我所知,它应该在 HTML 主页面上显示:全名是哈里森·里维斯到期日期为 01/23信用卡号码为 1234 5678 9012CVV 为 000
1 回答
莫回无
TA贡献1865条经验 获得超7个赞
看一下这个。使用此 $.getJSON 函数来获取 JSON 文件。
$.getJSON( "https://api.jsonbin.io/b/5e9535d3634f8d782606be53", function( parsed ) {
window.onload = testJSON();
function testJSON() {
$("#list").html("Full name is " + parsed.fname + " " + parsed.lname + "\nExpiration Date is " + parsed.expdate + "\nCredit Card # is " + parsed.creditcardnumber + "\nCVV is " + parsed.cvv);
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<pre id="list"></pre>
- 1 回答
- 0 关注
- 83 浏览
添加回答
举报
0/150
提交
取消