2
Good evening friends.
Next I need to pass a variable from a . js file to a Session and to pick up another page with php. The javascript function returns the first available time for marking a query, and I need to leave this set initially on another page.
var hr = now.getHours();
var min = now.getMinutes();
var time_format = hr + ":" + min;
//document.write ("<h3> Hoje é " + hr + ":" + min + ". </h3>");
//$('#next_time').html('28 de dezembro (sexta-feira) - 14:00 horas');
var seconds = now.getTime() / 1000;
var doctor_id = $('#doctor_id').val();
var clinic_id = $('#clinic_id').val();
$.ajax({
type: "GET",
url: base_url+"Searchdoctor/doctor_availability?"+"date="+seconds+"&doctor_id="+$('#doctor_id').val()+"&offset=0&clinic_id="+$('#clinic_id').val(),
success: function(result){
if(result.data.time_interval.length>0)
{
$('#schedule-consult-timeslot').html('<option disabled selected>'+'Horarios disponiveis'+'</option>');
$.each(result.data.time_interval, function (i, item) {
if(item.length != 0){
var split = item.time.split('-');
if(compararHora(time_format,split[0])){
$('#next_time').html(now.getDate ()+ ' de '+ monName[now.getMonth()]+ ' ('+dayName[now.getDay()]+') '+ '- '+ split[0]+ ' horas');
return false;
}
}
})
}else{
recursiveDate(1);
//console.log( adicionarDiasData(3) );
}
},
error: function(xhr, status, error) {
var err = eval("(" + xhr.responseText + ")");
alert(err.Message);
}
});
function compararHora(hora1, hora2)
{
hora1 = hora1.split(":");
hora2 = hora2.split(":");
var d = new Date();
var data1 = new Date(d.getFullYear(), d.getMonth(), d.getDate(), hora1[0], hora1[1]);
var data2 = new Date(d.getFullYear(), d.getMonth(), d.getDate(), hora2[0], hora2[1]);
return data1 < data2;
}
function recursiveDate(cont){
/*if(cont == 5){
console.log('parou');
}else{
console.log(cont);
cont = cont + 1;
recursiveDate(cont);
}*/
var seconds = adicionarDiasData(cont);
$.ajax({
type: "GET",
url: base_url+"Searchdoctor/doctor_availability?"+"date="+seconds+"&doctor_id="+doctor_id+"&offset=0&clinic_id="+clinic_id,
success: function(result){
if(result.data.time_interval.length>0)
{
$('#schedule-consult-timeslot').html('<option disabled selected>'+'Horarios disponiveis'+'</option>');
$.each(result.data.time_interval, function (i, item) {
if(item.length != 0){
var split = item.time.split('-');
date = getDateFormat(cont);
$('#next_time').html(date.getDate ()+ ' de '+ monName[date.getMonth()]+ ' ('+dayName[date.getDay()]+') '+ '- '+ split[0]+ ' horas');
//colocar a session com todos os dados acima;
return false;
}
})
}else{
cont = cont + 1;
recursiveDate(cont);
}
},
error: function(xhr, status, error) {
console.log(error);
}
});
}
function adicionarDiasData(dias){
var hoje = new Date();
var dataVenc = new Date(hoje.getTime() + (dias * 24 * 60 * 60 * 1000));
return dataVenc.getTime() / 1000;
//return dataVenc.getDate() + "/" + (dataVenc.getMonth() + 1) + "/" + dataVenc.getFullYear();
}
function getDateFormat(dias){
var hoje = new Date();
return new Date(hoje.getTime() + (dias * 24 * 60 * 60 * 1000));
}
what I need to pass to a SESSION is exactly what’s inside the id #next_time. Because I need to take another php page.
THAT -> date.getDate()+ ' from '+ monName[date.getMonth()]+ ('+dayName[date.getDay()]+') '+ '- '+ split[0]+ ' hours');
Thank you :)
I believe this post can help you: https://stackoverflow.com/questions/35091757/parse-javascript-fetch-in-php basically is to fetch a js by passing the variable on the body and retrieving it in php.
– Henrique Ramos
Maybe a
sessionStorage
from the JS itself. See in this answer how simple it is to create one and recover the value: https://answall.com/a/357226/8063– Sam