Skip to content

Instantly share code, notes, and snippets.

View ganeshpatil0101's full-sized avatar
😃
Learning new

Ganesh Patil ganeshpatil0101

😃
Learning new
View GitHub Profile
@ganeshpatil0101
ganeshpatil0101 / eventSourceExample2.js
Created October 13, 2022 17:04
Server Sent Event Example 2
const sendApiCall = document.getElementById('sendApiCall');
const output = document.getElementById('output');
const URL = (location.host === 'localhost:1234') ? '//localhost:3000/apitest' : 'https://righteous-quiet-sphynx.glitch.me/apitest';
const EURL = (location.host === 'localhost:1234') ? '//localhost:3000/esource' : 'https://righteous-quiet-sphynx.glitch.me/esource';
sendApiCall.addEventListener('click', () => {
// send api call
addLogs('Requesting server to process large data');
document.body.style.cursor = 'wait';
fetch(URL).then((res) => {
@ganeshpatil0101
ganeshpatil0101 / eventSourceExample.js
Created October 13, 2022 16:23
Event Source Example
const city = document.getElementById('city');
const label = document.getElementById('selected_city');
const form = document.getElementById('realTimeForm');
const secondsToUpdate = document.getElementById('seconds');
const close = document.getElementById('close');
const time = document.getElementById('time');
const URL = (location.host === 'localhost:1234') ? '//localhost:3000/event-stream' : 'https://righteous-quiet-sphynx.glitch.me/event-stream';
let selectedCityName = 'Asia/Calcutta';
let selectedCityValue = 'Asia/Calcutta';