The website operates smoothly when run locally, but encounters errors when deployed on GitHub and CodePen

The WeatherApp featured here leverages the OpenWeatherMap API to display a selected few weather results. I tested the code on my local system and then uploaded it to a GitHub repository to further examine it as a webpage. To my surprise, the code didn't function properly when accessed via a GitHub page or on CodePen. Are there any specific reasons for this issue? Visit the webpage: WeatherCheck

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://fonts.googleapis.com/css?family=Abril+Fatface" rel="stylesheet">
<style>

#container{ 
background-color: #3E5060;
margin: 20%;
padding: 2.5%;
}

body{
background-color: #B2D6F7;
font-family: 'Abril Fatface', cursive;
font-size: 300%;
color: white;
opacity: 0.7;
filter: alpha(opacity=70);
}

#demo {
font-size: 200%;
}
</style>
</head>
<body>

<div class = "text-center" id="container"> 
<img id = "demo0">          
<p id="demo"></p>
<p id="demo7"></p>
<div class="row">
<div class="col-sm-6">
<p id="demo1"></p>
</div>
<div class="col-sm-6">
<p id="demo2"></p>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<p id="demo3"></p>
</div>
<div class="col-sm-6">
<p id="demo4"></p>
</div>
</div>
<p id="demo6"></p>
<button onclick="getLocation()" style="color:black;">Click!</button>
</div>
<script>
var x = document.getElementById("demo");
var x1 = document.getElementById("demo1");
var x2 = document.getElementById("demo2");
var x3 = document.getElementById("demo3");
var x4 = document.getElementById("demo4");
var x5 = document.getElementById("demo0");
var x6 = document.getElementById("demo6");
var x7 = document.getElementById("demo7");

function getLocation() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition);
    } else { 
        x.innerHTML = "Geolocation is not supported by this browser.";
    }
}

function showPosition(position) {
    latitude = position.coords.latitude; 
    longitude =  position.coords.longitude;
    console.log(latitude);
    getData(latitude, longitude);
}

function getData(lat,long)
{
    console.log(long);
    var API_KEY = "*************************";
    var apiUrl = "http://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + long + "&units=metric&appid=" + API_KEY;
    var xhr = new XMLHttpRequest();
    xhr.open("GET", apiUrl, false);
    xhr.send();
    console.log(xhr.status);
    console.log(xhr.statusText);

    response = JSON.parse(xhr.response);
    console.log(xhr.response);
    console.log(response.weather[0].icon);
    x.innerHTML = response.name;
    x1.innerHTML = parseInt(response.main.temp_max);
    x2.innerHTML = response.main.humidity;
    x3.innerHTML = response.wind.speed;
    x4.innerHTML = response.wind.deg;
    x5.src = "http://openweathermap.org/img/w/" + response.weather[0].icon + ".png";
    x6.innerHTML = response.weather[0].description;
    var date = new Date();
    console.log(date.getHours()>12);
    x7.innerHTML = date.getHours() + ":" + date.getMinutes();
    if(date.getHours()>17 || date.getHours()<5){
        document.getElementById("container").style.background= "#B2D6F7";
        document.body.style.background= "#3E5060";      
    }
}
</script>

</body>
</html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issues with Typescript when Adding Objects to an Array in a Function

In my Angular 2 application, I am encountering a problem when trying to add new items to an array. The issue appears to be related to Typescript types, although I'm not entirely certain. Here is the current structure of the array I am attempting to mo ...

Converting a mention tag text to a <router-link> in VUEJS: Step-by-step guide

I have a body property in my data data(){ return{ body:'Hello! I am @user3 and @user4' } } I am looking to transform each @user into a clickable link that redirects to their specific URL path. <router-link :to="`/${username1}`"& ...

Conflicting CSS files in Next.js

I recently started using Next.js and I am in need of a solution to my current problem along with some advice. Problem: -When accessing the empty URL (just localhost:8081), a login form is displayed, with an option to switch to the Register component with ...

Eliminate the approximately 20 pixel space on the right side of the HTML email when viewed on iOS

Recently, I've been focused on developing a contact form for my portfolio website. Successfully sending HTML emails from the server to my email address has been a highlight. Since I mainly access my emails on my iPod Touch, I tailored the mail templat ...

Leveraging the power of Redis client within an Express router

I would like to incorporate the use of a redis client in specific endpoints of my application. Here is how my app.js file is currently structured: //app.js const redis = require('redis'); const client = redis.createClient(process.env.REDIS_POR ...

Styling elements based on a condition with CSS

Is there a way to confirm the truthiness of a TypeScript variable using CSS? I am attempting to determine if I am on a particular page so that I can adjust the height accordingly. Appreciate any help! ...

Utilizing AJAX requests in PHP's MVC framework

I am currently working on a game site using a combination of php and javascript. All my classes and data are stored in php and then encoded into json format. The view calls a javascript file which, through an ajax request, retrieves the php data encoded in ...

Issue with AJAX POST method failing to upload the file

I'm having trouble incorporating file upload support into my AJAX post function. Can anyone provide some guidance on what I might be missing? function ajax_post(url, param) { if (url.substr(0, 11) == 'javascript:') { result = &ap ...

Words of wisdom shared on social media

How can I share text from my HTML page on Twitter? This is the code snippet from my HTML page - function change() { quotes = ["Naam toh suna hi hoga", "Mogambo Khush Hua", "Kitne aadmi the?"]; auth = ["Raj", "Mogambo", "Gabbar"]; min = 0; max = ...

What methods can be used to disable a JavaScript function, such as utilizing hasClass()?

I am currently customizing a WordPress theme to load posts and pages using AJAX. I have successfully implemented this functionality with the code snippet below, but now I need to prevent the AJAX function from running when clicking on the logo that links t ...

Issue: The CSS loader did not provide a valid string output in Angular version 12.1.1

I am encountering 2 error messages when trying to compile my new project: Error: Module not found: Error: Can't resolve 'C:/Users/Avishek/Documents/practice/frontend/src/app/pages/admin/authentication/authentication.component.css' in &apos ...

Concealing Vimeo's controls and substituting them with a play/pause toggle button

I'm currently working on implementing the techniques demonstrated in this tutorial (), but unfortunately the code in the fiddle I put together doesn't appear to be functioning correctly. I'm at a loss as to what might be causing this issue. ...

I'm experiencing an issue with my Bootstrap Navbar Toggle not toggling

Struggling for weeks now to figure out what's wrong with this code. It works perfectly until I resize the browser, then the menu stays open no matter how many times I click the toggle. I want it to be closed by default and only open when the toggle is ...

Ensure no duplicate values are pushed into array when using angularjs foreach loop

I have a specific array that I am using in my foreach function $scope.categoryList = [ { "id": 44, "creationTimestamp": "2019-11-15 17:11:17", "name": "FIXED ", " ...

How can CSS be used to create a responsive form script?

We have enlisted the services of an SEO provider through upcity.com, which necessitates us to embed a form on our website. However, we are facing challenges with the responsiveness of the form on mobile devices, which undermines our efforts. Therefore, I a ...

Leveraging external data for testing in Protractor script

I am encountering an issue while attempting to access test data using JSON, as it keeps showing up as undefined. I am implementing a Page Object Model and trying to reference external test data. However, when passing the values from my test data into a fun ...

The second JSP page fails to load following an AJAX POST request

The following code snippet is found in page1.jsp. $.ajax({ type: "post", url: "page2.jsp", data: newdata, success:function(msg){ return msg; } ...

The utilization of useState can potentially trigger an endless loop

Currently, I am in the process of developing a web application using Next.js and Tailwind CSS. My goal is to pass a set of data between methods by utilizing useState. However, I have encountered an issue where the application loads indefinitely with excess ...

issue with react-adsense leading to numerous problems

I am currently working on integrating AdSense into my React application, but I am facing challenges in understanding the process. Despite going through the documentation for npm react-adsense, I am still confused about where exactly to place the ad code. H ...

Searching for a specific element in Vue.js using its unique identifier (ID) can be

I have a new project using Vue. It includes a div that loops through title and data. Inside the div, there is a search filter and content that renders in p tags. The p tags also go through a loop. Take a look at the code below: <div> <div v- ...