First release of how I changed the challenge.
This commit is contained in:
85
assets/js/system.js
Normal file
85
assets/js/system.js
Normal file
@@ -0,0 +1,85 @@
|
||||
function btnFind()
|
||||
{
|
||||
// Reset Rows
|
||||
$("#alertBox").hide();
|
||||
$(".alert").html("");
|
||||
$('.alert').removeClass('alert-warning').removeClass('alert-danger').addClass('alert-warning');
|
||||
$("#spinnerBox").hide();
|
||||
$("#txtOutput").hide();
|
||||
|
||||
// Set Vars
|
||||
let txtAddress = $("#txtAddress").val() + "";
|
||||
// Quick test to make sure address was entered.
|
||||
if (txtAddress === "")
|
||||
{
|
||||
$(".alert").html("You have to enter an address first.");
|
||||
$("#alertBox").show();
|
||||
return;
|
||||
}
|
||||
|
||||
// Show Spinner
|
||||
$("#spinnerBox").show();
|
||||
|
||||
// API - Call geocode API
|
||||
// K = (Required) Key, allows access to API
|
||||
// C = (Required) Command,
|
||||
// LL - Will return the Lat/Lon of a given address.
|
||||
// DIST - Will return the distance information.
|
||||
// T = (Optional) Test, Test Mode = 1 will only pull one record from the DB
|
||||
// ADDRESS = Address you want to return the Lat/Lon or Distance from.
|
||||
$.ajax(
|
||||
{
|
||||
url : 'https://rhays.us/Examples/RX_API_Two/RX2.php',
|
||||
type : 'GET',
|
||||
dataType: 'json',
|
||||
data :
|
||||
{
|
||||
'K' : 'RLH4321',
|
||||
'C' : 'DIST',
|
||||
'T' : '1',
|
||||
'address' : txtAddress,
|
||||
},
|
||||
success : function(data)
|
||||
{
|
||||
switch(data.status.toUpperCase())
|
||||
{
|
||||
case 'OK':
|
||||
sOutput = '<p>The Pharmacy closest to the address location you entered is: </p>';
|
||||
sOutput = sOutput + 'Pharmacy: <b>' + data.pharmacy + '</b><br/>';
|
||||
sOutput = sOutput + 'Address: <b>' + data.address + '</b><br/>';
|
||||
sOutput = sOutput + 'City: <b>' + data.city + '</b><br/>';
|
||||
sOutput = sOutput + 'State: <b>' + data.state + '</b><br/>';
|
||||
sOutput = sOutput + 'Zip: <b>' + data.zip + '</b><br/><br/>';
|
||||
sOutput = sOutput + '<p>Approx. Drive time and distance:</p>';
|
||||
sOutput = sOutput + 'Distance: <b>' + data.distance + '</b><br/>';
|
||||
sOutput = sOutput + 'Duration: <b>' + data.duration + '</b><br/>';
|
||||
|
||||
$("#txtOutput").html(sOutput);
|
||||
$("#spinnerBox").hide();
|
||||
$("#txtOutput").show();
|
||||
break;
|
||||
case 'ERROR':
|
||||
$("#spinnerBox").hide();
|
||||
$('.alert').removeClass('alert-warning').removeClass('alert-danger').addClass('alert-danger');
|
||||
$(".alert").html(JSON.stringify('Error code: ' + data.code + ' - ' + data.description));
|
||||
$("#alertBox").show();
|
||||
break;
|
||||
}
|
||||
},
|
||||
error : function(request,error)
|
||||
{
|
||||
$("#spinnerBox").hide();
|
||||
$('.alert').removeClass('alert-warning').removeClass('alert-danger').addClass('alert-danger');
|
||||
$(".alert").html('SYSTEM.JS<br/> ' + JSON.stringify(request));
|
||||
$("#alertBox").show();
|
||||
return;
|
||||
},
|
||||
// TODO: Hook to put in status codes
|
||||
// statusCode:
|
||||
// {
|
||||
// 404: function() {
|
||||
// alert( "page not found" );
|
||||
// }
|
||||
// },
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user