0
I take in my JS the month the user chose in the HTML select, if in case the value month has been set it executes the function Filter_data_bank as the value, if not I define that the value will be "m", but it does not make the request and is just falling in the error condition. I hoped he’d show me "okay".
Code:
ajax.js
$(function(){
mostraMesSelect();
var mes = pegaMesSelect();
if(typeof mes == "undefined"){
Filtra_data_Banco("m");
}else{
Filtra_data_Banco(mes);
}
});
function Filtra_data_Banco(valor){
$.ajax({
type: "POST",
url: 'ajax-FiltrosDashboard.php',
data:{
mesSelect:valor
},
dataType: "json",
success:function(data){
console.log(data);
},
error:function(){
console.log("Erro indesperado "+ valor);
}
});
}
function pegaMesSelect(){
var mesValue = $("#mesSelect");
mesValue.change(function(){
console.log(mesValue.val());
return mesValue;
});
}
function mostraMesSelect(){
$("#mesSelect").change(function(){
var mesText = $("#mesSelect option:selected").text();
$("#mesSelecionado").html('<h2 class="text-center">'+mesText+'</h2>');
});
}
ajax-Filtrosdashboard.php
<?php
if($_POST['mesSelect']){
echo json_encode($_POST['mesSelect']);
}
Console Output:
Change json_encoder to json_encode
– Felipe Duarte
Even so, without success
– Alexandre Vieira de Souza
Try debuggar by browser(Developer Tool), make sure that the console tab displays any errors. You can also view in the network tab if the ajax-Filtrosdashboard.php page was called correctly and which parameters were sent.
– Caique Romero