Jump to content

Make JavaScript variable external data?


phagen

Recommended Posts

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...