简体   繁体   English

为什么我不能使用 RequireJS 解析 JavaScript 中的 config.json 文件?

[英]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.

相关问题 在 Vue CLI 3 中运行 build:electron 后,如何将静态 config.json 文件中的值读取到 Vue 文件中的 TypeScript? - How can I read values from a static config.json file to TypeScript in a Vue file after running build:electron in Vue CLI 3? 为什么我不能用Javascript打开()和解析()这个JSON文件? - Why can't I open() and parse() this JSON file in Javascript? 为什么我无法从我的requirejs配置访问我的REST网址 - Why can't I access my REST urls from my requirejs config 为什么我无法在JavaScript中解析JSON? - Why I can't parse JSON in JavaScript? 如何使用Gulp通过config.json文件替换HTML属性中的值? - How I replace values in HTML attributes via config.json file with Gulp? 使用config.json文件设置Dojox.app缓存的存储 - Setting up a Dojox.app cached store using config.json file Javascript函数根据URL加载不同的config.json文件 - Javascript function to load different config.json files depending on URL 电子:我的自定义config.json未加载 - Electron: my custom config.json is not being loaded 如何循环获取从 config.json 文件中获取的大量值 - How to loop for an amount of values got from a config.json file 错误:ENOENT:没有这样的文件或目录,打开“../config.json” - Error: ENOENT: no such file or directory, open '../config.json'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM