Return via Ajax data in an input type date with Jquery

Asked

Viewed 364 times

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 $selInfoTasks= new Tasks();&#xA;&#xA;if($_SERVER['REQUEST_METHOD']=='POST'){&#xA;&#xA; $idTask = $_POST['info-task']; &#xA; $stInfoTasks = $selInfoTasks->selectInfoTask($idTask);&#xA;&#xA; echo json_encode($stInfoTasks);&#xA;&#xA; exit();&#xA;}

1 answer

3


Failed to transform the text sent by PHP into a valid json, responseData.Delivery does nothing.

Change:

$(".delivery-info").val(responseData.Delivery);  

To:

var res = JSON.parse(responseData);
$(".delivery-info").val(res.Delivery);  
  • Not going, I was reading a documentation here about the date field in the input, and I will have to leave as text the same type.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.