phagen Posted February 14, 2023 Share Posted February 14, 2023 In a script tag in my HTML file I have a JavaScript function as such. Notice the part where it I create the variable const event = { . My question how in the same folder as the HTML file could I create a file that is only the event variable and refer to in in the code. Could this externally referenced data be a JSON file? Thanks async function insertEvents() { let response; try { const event = { 'summary': 'Martha Dentist', 'location': '800 Howard St., San Francisco, CA 94103', 'description': 'Take Martha to dentist.', 'start': { 'dateTime': '2023-02-28T07:00:00-07:00', 'timeZone': 'America/Los_Angeles' }, 'end': { 'dateTime': '2023-02-28T08:00:00-07:00', 'timeZone': 'America/Los_Angeles' }, 'recurrence': [ 'RRULE:FREQ=DAILY;COUNT=8' ], 'attendees': [ {'email': 'charles@datatech.com'}, {'email': 'datatech@gmail.com'} ], 'reminders': { 'useDefault': false, 'overrides': [ {'method': 'email', 'minutes': 24 * 60}, {'method': 'popup', 'minutes': 10} ] } }; const request = { 'calendarId': 'primary', 'resource': event }; response = await gapi.client.calendar.events.insert(request); } catch (err) { document.getElementById('content').innerText = err.message; return; } const events = response.result.items; if (!events || events.length == 0) { document.getElementById('content').innerText = 'No events found.'; return; } } Link to comment Share on other sites More sharing options...
dsonesuk Posted February 17, 2023 Share Posted February 17, 2023 create external JSON file and use Ajax to read file contents, clear current, add new, OR append new to current using server language then reread that JSON file to: const event ( don't think variable event won't be allowed being JavaScript 'keyword' an all. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now