I have created a table that displays information from Geonames API. I am now trying to set up a function for catching an error when the user leaves the input fields empty and sends an alert to the interface. This is my code below. I'm struggling to understand how I do this.
$("#btnWeatherRun").click(function () {
$.ajax({url: "libs/php/weather.php",type: "GET",
dataType: "json",
data: {
north: $("#north").val(),
south: $("#south").val(),
east: $("#east").val(),
west: $("#west").val(),
},
success: function (result) {
console.log(result);if (result.status.name == "ok") {
$("#outputDate").html(
result["data"]["weatherObservations"][0]["datetime"]
);
$("#outputStationName").html(
result["data"]["weatherObservations"][0]["stationName"]
);
$("#outputTemperature").html(
result["data"]["weatherObservations"][0]["temperature"]
);
$("#outputHumidity").html(
result["data"]["weatherObservations"][0]["humidity"]
);
$("#outweatherCondition").html(
result["data"]["weatherObservations"][0]["weatherCondition"]
);
$("#outputWindSpeed").html(
result["data"]["weatherObservations"][0]["windSpeed"]
);
}
},
error: function (jqXHR, textStatus, errorThrown) {
if (data === "") {
alert("there is an error");
}
},
});
});
You can just use
window.onerror!e.g.
That entire function just alerts you when you get an error!!!
Also, don't use caps on your titles