Javascript require() function giving ReferenceError: require is not defined
RequireJS is a JavaScript file and module loader. It is optimized for
in-browser use, but it can be used in other JavaScript environments,
like Rhino and Node. Using a modular script loader like RequireJS will
improve the speed and quality of your code.IE 6+ .......... compatible ✔
Firefox 2+ ..... compatible ✔
Safari 3.2+ .... compatible ✔
Chrome 3+ ...... compatible ✔
Opera 10+ ...... compatible ✔
http://requirejs.org/docs/download.html
Add this to your project: https://requirejs.org/docs/release/2.3.5/minified/require.js
and take a look at this http://requirejs.org/docs/api.html
How to fix Uncaught ReferenceError: require is not defined
You don´t need to import fetch, its part of JS.
var apikey="https://opentdb.com/api.php?amount=10";
fetch(apikey) .then(response => response.json()) .then(json => { // console.log(json); console.log(json.results[0].question); });
Related Topics
What's the Best Way to Make a D3.Js Visualisation Layout Responsive
5Xx or 4Xx Error with "No 'Access-Control-Allow-Origin' Header Is Present"
Unexpected Token Colon JSON After Jquery.Ajax#Get
JavaScript Get Xpath of a Node
How Might I Find the Largest Number Contained in a JavaScript Array
Is There Ever a Good Reason to Pass a String to Settimeout
Scope of Sessionstorage and Localstorage
How to Load Images Dynamically (Or Lazily) When Users Scrolls Them into View
Trigger CSS Animations in JavaScript
Detect Rotation of Android Phone in the Browser with JavaScript
How to Chop/Slice/Trim Off Last Character in String Using JavaScript
Why Is My Infinite Loop Blocking When It Is in an Async Function
Determine Original Size of Image Cross Browser
JavaScript "Addeventlistener" Event Fires on Page Load
Hide Scrollbar While Still Being Able to Scroll with Mouse/Keyboard