How to read json files using javascript without using require - javascript

Whenever i tried to read my json file using the require function and using my js file from the browser an error shows " require function is not defined" so i want another method to read the json file , and if you can plz mention how to read, update, delete, insert to the json file
as i mention before i have tried using the require function , and also using the import function but using it make the situation worse since whenever i tried to use any function through the html an error shows say
"Uncaught ReferenceError: Login is not defined
at HTMLButtonElement.onclick"

Related

Access .env file from Content Script

Is it possible to access variables from .env file from Content Script?
I am building a Chrome Extension and I have javascript Content Script file from which I listen to events on the browser page.
I would like to make an API call, so I need to access my API key, which is stored in .env file. When i try to call variables as const key = proccess.env.API_KEY i get an error: Uncaught ReferenceError: process is not defined.
I tried require('dotenv').config(); to help me with that problem, but since this is a normal js file and not Node.js, i get an erorr: Uncaught ReferenceError: require is not defined
So is there a way to load .env variables in normal JavaScript? Or should I use different approach?

How to use Feather Icons in XPages?

I already tried using the CDN version, adding the feather.min.js file locally and even copy-pasting the script in the xpage output script control but still I'm getting an Uncaught ReferenceError: feather... when I call feather.replace().

How to exit javascript / node.js inside HTML

I have json file ( I create this json file using node.js) that I read in HTML using json2html library and if the json file is present / readble then it will be uploaded in our server.
I have json2html code that reads json file and prints HTML page based on content of json file. If json file is unreadable or not present, then I want node.js / javascript to stop or exit the process so nothing gets uploaded to server. How shall I stop / exit the code from processing further if json file is not available.
I do have process.exit() in my HTML file where I read json file . It does not exit gracefully. When I do inspect elements, it errors Uncaught (in promise) ReferenceError: process is not defined. I do have npm i process even though process is global. I still explicitly define const process = require('process'); in my index.js file. Still I get error while opening my html file in browser. How to get past this error. Please refer below for my code from my html file
let responseContent = fetch('studentRecords.json')
.then(function(response) {
return response.json();
})
.catch(function(err) {
process.exit(1);
});
The problem here is that you are trying to reference process which is a node global variable from the browser in your HTML file. Because of this, it won't exist.
Based on what you've mentioned, you can leave the code block as is and instead of running process.exit(1) you could try logging out an error or wrapping it in a callback function and returning an error instead? That way it won't try to process the fetch response and it will have the option to continue in the way you see fit.

Loading external data into a SproutCore app

I have a sample SproutCore app at https://github.com/ericgorr/myproject. The app is *sc_technique* inside of the project. This app is based upon the gist at https://gist.github.com/mauritslamers/5384031.
As best I understand the technique being described, the external data to be loaded is stored in the helper.js file. For example:
MyApp.statechart.sendEvent("loadData",[{ folder: "name": files: ["filename1.js"] }]);
It is then added to the document as a javascript script. The lines of the script are executed to generate events and the data is added to the app's SC.Store. After the script executes, it is removed.
When I attempt to implement this technique in my own app, I cannot get it to work. The error I am getting is:
Uncaught SyntaxError: Unexpected token : helper.js:1
It seems as if the app is trying to load the helper.js file before I tell it to do so. I get this error at the app first launches and before it executes the first line in main.js.
I know there are other problems in this app, but I cannot work on those until I can get past this problem.
as the browser is pointing out: there is a syntax error in the helper.js file:
the colon after "name" should be a comma.

CKEditor external file browser

I'm trying to return file url from external file browser to CKEditor but I'm receiving error which is:
[09:02:18.038] TypeError: A._.filebrowserSe is undefined # http://www.xxx.pl/yyy/js/ckeditor/ckeditor.js:56
I'm using this code:
window.parent.opener.CKEDITOR.tools.callFunction(number,url);
Does anyone know how to solve this issue?
Here is an answer: How can you integrate a custom file browser/uploader with CKEditor?
You should to receive GET parameter called CKEditorFuncNum.
I use it such way in php:
window.parent.CKEDITOR.tools.callFunction(<?=intval($_REQUEST['CKEditorFuncNum'])?>, url, message);

Categories

Resources