JSFiddle - React, Tailwind, and code Playground

by gsferreira

HTML

<input type="text" id="txt"/>

<input type="button" id="btn" />

JavaScript

var count = 0;

$('#txt').blur(function() {
count = count + 1;                
    getWeatherData(41,-8);
    
                });
    
    
    
    
    $('#btn').click(function()
                    {
                        if(count>0) {
        console.log('Waiting for your location...');
        setTimeout(function(){ $('#btn').click(); }, 500); // Try to submit form after timeout
        return false;
                        }else
                        {
                           alert('y ' + count); 
                        }
                        
                    });


function getWeatherData(latitude, longitude) {
    var temperature = 0;
    var dfd = $.Deferred();
    var url = "http://api.openweathermap.org/data/2.5/weather?lat=";
    url += latitude;
    url += "&lon=";
    url += longitude;
    url += "&cnt=1";
    $.ajax({
        type: "POST",
        dataType: "jsonp",
        url: url + "&callback=?",
        async: false,
        success: function (data) {
            count = count - 1;
        },
        error: function (errorData) {
            alert("Error while getting weather data :: " + errorData.status);
        }
    });
    return dfd.promise();
}