good evening I have the following script:
$(document).ready(function() {
$.ajax({
dataType: "json",
data: [],
url: "https://ubicaciones.paginasweb.cr/provincias.json",
type: 'GET',
crossDomain: true,
success: function(data) {
agregarProvincias(data);
}
});
$(document).on('change', '#provincia > select', function() {
var provincia = this.value;
$.ajax({
dataType: "json",
url: "https://ubicaciones.paginasweb.cr/provincia/" + provincia + "/cantones.json",
data: {},
success: function(data) {
agregarCantones(data);
}
});
});
$(document).on('change', '#canton > select', function() {
var provincia = $('select#provincia').val();
var canton = this.value ;
$.ajax({
dataType: "json",
url: "https://ubicaciones.paginasweb.cr/provincia/" + provincia + "/canton/" + canton + "/distritos.json",
data: {},
success: function(data) {
agregarDistritos(data);
}
});
});
function agregarProvincias(data) {
var html = "<select id='provincia'>";
for (key in data) {
html += "<option value='" + key + "'>" + data[key] + "</option>";
}
html += "</select";
$('#provincia').html(html);
}
function agregarCantones(data) {
var html = "<select>";
for (key in data) {
html += "<option value='" + key + "'>" + data[key] + "</option>";
}
html += "</select";
$('#canton').html(html);
}
function agregarDistritos(data) {
var html = "<select>";
for (key in data) {
html += "<option value='" + key + "'>" + data[key] + "</option>";
}
html += "</select";
$('#distrito').html(html);
}
});
and I charge it in the following html:
<html>
<head>
<title>Obteniendo las provincias</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<meta charset="utf-8">
<script type="text/javascript" src="js/js_pronvincias_cantontes_distritos.js"></script>
</head>
<br>
<div id="provincia"></div>
<div id="canton"></div>
<div id="distrito"></div>
</body>
</html>
My question is how can I get the values of the div and then insert a database into a php.