Answer the question
In order to leave comments, you need to log in
Chrome extension, why is the javascript code not working?
I can't understand why the javascript code in the chrome extension does not work! Another javascript code works well (code for date/time)
javascript code (jQuery):
(function ($) {
$.get("http://ipinfo.io", function (response) {
$("#ip").html("IP: " + response.ip);
$("#weather-city").html(response.city);
$(document).ready(function() {
$('#weather_city').val(response.city),
$('#units_metric').val('metric');
processForm();
});
}, "jsonp");
/**
* Callback to process the form.
*/
function processForm() {
// Fetch the data from the public API through JSONP.
// See http://openweathermap.org/API
$.ajax({
url: 'http://api.openweathermap.org/data/2.5/weather',
jsonp: 'callback',
dataType: 'jsonp',
cache: false,
data: {
q: $('#weather_city').val(),
units: 'metric'
},
// work with the response
success: function (response) {
$('#weather_description').text(response.weather[0].description);
$('#weather-temprature').text(response.main.temp);
},
});
}
})(jQuery);
<head></head>
<script type='text/javascript' src='assets/js/weather.js'></script>
<div class='header-weather'>
<div id="weather-city"></div>
<span id="weather-temprature"></span> °C
<form id="weather_status_form">
<input type="hidden" id="weather_city" name="city" />
</form>
</div>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question