[英]Why can I not parse my config.json file in JavaScript using RequireJS?
I have no idea why I'm not able to parse this JSON file in JS using RequireJS.我不知道为什么我无法使用 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>
To my knowledge, it should show this on the main HTML page:据我所知,它应该在 HTML 主页面上显示:
Full name is Harrison Reeves全名是哈里森·里夫斯
Expiration Date is 01/23截止日期为 01/23
Credit Card # is 1234 5678 9012信用卡号码是 1234 5678 9012
CVV is 000 CVV 为 000
Check this out.看一下这个。 Used this $.getJSON function to fetch a JSON file.
使用这个 $.getJSON function 来获取 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.