I have a form where the user submits info (name, address, phone, etc.) and on submit, the data will be inserted into the API url, sent to the API, data is returned and put into hidden fields then posted. Is it possible to hide the AJAX URL inside a php file so I can hide the API KEY so it's not public? Like:
$.ajax({
url: whitepages.php
Inside whitepages.php
Here is my existing code:
var wpfname = $('#customer_person_name_f input').val();
var wplname = $('#customer_person_name_l input').val();
var wpfullname = wpfname + " " + wplname;
var wpaddress = $('#customer_address_street input').val();
var wpcity = $('#customer_address_city input').val();
var wpstate = $('#address_state_abbr input').val();
var wpzip = $('#customer_address_zipcode input').val();
var wpphone = $('#customer_phone_number input').val();
var wpemail = $('#customer_email_address input').val();
$.ajax({
url: "https://proapi.whitepages.com/3.3/lead_verify.json?name=" + wpfullname +"&phone=" + wpphone + "&address.street_line_1=" + wpaddress + "&api_key=" + KEYGOESHERE + "&address.city=" + wpcity + "&address.postal_code=" + wpzip + "&address.state_code=" + wpstate + "&email_address=" + wpemail,
dataType: "text",
method: "GET",
crossDomain: "true",
success: function(data) {
var json = $.parseJSON(data);
console.log(json);
$('#wp_phone_contact_score').val(json.phone_checks.phone_contact_score);
$('#wp_subscriber_name').val(json.phone_checks.subscriber_name);
$('#wp_subscriber_age_range').val(json.phone_checks.subscriber_age_range);
$('#wp_subscriber_address').val(json.phone_checks.subscriber_address.street_line_1 +', ' + json.phone_checks.subscriber_address.city +', ' + json.phone_checks.subscriber_address.state_code + ' ' + json.phone_checks.subscriber_address.postal_code);
$('#wp_line_type').val(json.phone_checks.line_type);
$('#wp_is_commercial').val(json.phone_checks.is_commercial);
$('#wp_address_contact_score').val(json.address_checks.address_contact_score);
$('#wp_is_active').val(json.address_checks.is_active);
$('#wp_address_to_name').val(json.address_checks.address_to_name);
$('#wp_resident_age_range').val(json.address_checks.resident_age_range);
$('#wp_resident_phone').val(json.address_checks.resident_phone);
$('#wp_type').val(json.address_checks.type);
}
<form>
<input id="wp_phone_contact_score" type="hidden" name="customer_wp_phone_contact_score" value="">
<input id="wp_subscriber_name" type="hidden" name="customer_wp_subscriber_name" value="">
<input id="wp_subscriber_age_range" type="hidden" name="customer_wp_subscriber_age_range" value="">
<input id="wp_subscriber_address" type="hidden" name="customer_wp_subscriber_address" value="">
<input id="wp_line_type" type="hidden" name="customer_wp_line_type" value="">
<input id="wp_is_commercial" type="hidden" name="customer_wp_is_commercial" value="">
<input id="wp_address_contact_score" type="hidden" name="customer_wp_address_contact_score" value="">
<input id="wp_is_active" type="hidden" name="customer_wp_is_active" value="">
<input id="wp_address_to_name" type="hidden" name="customer_wp_address_to_name" value="">
<input id="wp_resident_age_range" type="hidden" name="customer_wp_resident_age_range" value="">
<input id="wp_resident_phone" type="hidden" name="customer_wp_resident_phone" value="">
<input id="wp_type" type="hidden" name="customer_wp_type" value="">
<input type="text" name="customer_person_name_f">
<input type="text" name="customer_person_name_l">
<input type="text" name="customer_phone_number">
<input type="text" name="customer_address_street">
<input type="text" name="customer_address_city">
<input type="text" name="customer_address_state_abbr">
<input type="text" name="customer_address_zipcode">
<input type="submit" id="submitBtn" class="btn btn-primary btn-large" value="Submit"/>
</form>