0
I have the following Ajax code:
$.ajax({
type:"post",
url:"../connect/post/infoTask.php",
data:'info-task='+idtask,
success:function(responseData){
$(".delivery-info").val(responseData.Delivery);
}
});
Return Json to Ajax:
$selInfoTasks= new Tasks();
if($_SERVER['REQUEST_METHOD']=='POST'){
$idTask = $_POST['info-task'];
$stInfoTasks = $selInfoTasks->selectInfoTask($idTask);
echo json_encode($stInfoTasks);
exit();
}
Via the Task Id it looks for various information, in this case I just put the Delivery, which is what interests me.
I return the Delivery which is a field DATE at the bank:
public function selectInfoTask($idTask){
try {
$stmt = $this->conn->prepare("SELECT Tasks.*,
DATE_FORMAT( tasks.Delivery , '%d/%m/%Y' )
AS Delivery
FROM Tasks
WHERE TasksId = $idTask");
$stmt->execute();
return $stmt->fetch(PDO::FETCH_ASSOC);
}catch (PDOException $exception){
header("Location: ./error.php?err=Unable-to-find-info");
echo 'Error: '.$excption->getMessage();
return null;
}
}
}
In SELECT I already put in the format I want.
But when I send this one to the country:
<label>Entrega</label>
<div class="input-group">
<input id="delivery-info" type="date" class="form-control task-viewer delivery-info" disabled>
<span class="input-group-btn">
<span class="btn"><i class="fa fa-calendar" aria-hidden="true"></i></span>
</span>
</div>
Code that returns the query for javascript:
$selInfoTasks= new Tasks();
if($_SERVER['REQUEST_METHOD']=='POST'){ $idTask = $_POST['info-task'];
$stInfoTasks = $selInfoTasks->selectInfoTask($idTask);
echo json_encode($stInfoTasks);
exit();
}
He doesn’t fill in the date, anyone has any idea?
Where vc returns json or text for javascript?
– rray
@rray
$selInfoTasks= new Tasks();

if($_SERVER['REQUEST_METHOD']=='POST'){

 $idTask = $_POST['info-task']; 
 $stInfoTasks = $selInfoTasks->selectInfoTask($idTask);

 echo json_encode($stInfoTasks);

 exit();
}
– Wagner Viana