I have no idea why I'm not able to parse this JSON file in JS using RequireJS.
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:
Full name is Harrison Reeves
Expiration Date is 01/23
Credit Card # is 1234 5678 9012
CVV is 000
Check this out. Used this $.getJSON function to fetch a JSON file.
$.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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.