I made top menu in wp admin dashboard. There I will have input field. It will be input where admin can enter Google locations. After picking correct location admin will press save and location will be saved into wordpress database in locations table. For now I made text input field only to test it. I have:
<form id="location_form" method="post" action="save-locations.php">
<table class="form-table">
<tr valign="top">
<th scope="row">Enter location:</th>
<td>
<div class="container">
<div class="row">
<input type="text" id="username" name="username" placeholder="Username" autocomplete="off" class="required"/>
</div>
</td>
</tr>
<input id="submit" name="submit" type="submit" value="Send It" />
</form>
<div id="response"></div>
</div>
Than I have save-location.php located in wp-admin folder where I make sql insert into db and I have validate.js where I have aja call:
function ajaxSubmit() {
//loading circle so user can see something is happening
$('#submit').attr('disabled', 'disabled');
//collect data
var username = $('#username').val();
//put data in one variable
var data = 'username=' + username;
$.ajax({
url: "save-location.php", //send it to php to handle data
type: 'get',
dataType: 'json',
data: data,
cache: false,
success: function (response) {
if (response.error != 'true') {
$('#response').html('<h3>Records added successfully.</h3>').fadeIn('slow');
}
else {
$('#response').html('<h3>Could not able to execute sql</h3>').fadeIn('slow');
}
},
error: function (jqXHR, textStatus, errorThrown) {
$('#response').text('Error Thrown: ' + errorThrown + '<br>jqXHR: ' + jqXHR + '<br>textStatus: ' + textStatus).show();
}
});
return false;
}
But nothing happens. Where I made msitake?