I have searched as much as I can throughout here and elsewhere trying to solve this; I can't seem to find something similar enough. The button click fires as it prints to the console. However, every console response I ask for afterwards does not happen, leading me to believe that the AJAX call itself is not firing.
<form type="GET" action="/api.php" id="search" name="search">
<label for="getICAO">Search by ICAO:</label><br />
<input type="text" id="getICAO" name="getICAO" placeholder="KLAX"><br />
<label for="getCity">Search by city:</label><br />
<input type="text" id="getCity" name="getCity"> <br />
<label for="button"><input type="button" id="submit" name="submit" value="Find Airport"> </label><br />
</form>
<script>
jQuery("#submit").on("click", function(e) {
e.preventDefault();
console.log('submitted');
// This part works ^
// I have verified that the variables are passed to the PHP file. The PHP file is
//functioning properly and the database query returns with JSON formatted results.
var getICAO = jQuery("#getICAO").val();
var getCity = jQuery("#getCity").val();
jQuery.ajax({
type: "GET",
url: "/api.php?getICAO="+getICAO+"&getCity="+getCity,
dataType: "json",
}) .done(function(data) {
var result = jQuery.parseJSON(data);
jQuery.each(result, function(key, value) {
console.log(result); // Nothing returns
});
})
});
</script>
This is likely a simple error that I just don't understand. Thank you for your help.