how to recover json php data with ajax

0

How can I retrieve data coming from a page in php with ajax . because I am getting the result but it is not coming to jquery it does not bring me the values

Query code

if(isset($_POST['cep'])){
    $cep = $_POST['cep'];
    $newCep = str_replace("-", "", $cep);

    require_once "../Model/Correios.class.php";

    $p = new Correios("15991182","{$newCep}","0.300","5","11","11","0","04510");
    $s = new Correios("15991182","{$newCep}","0.300","5","11","11","0","04014");

    $pac = $p->getValor();
    $prazoPac = $p->getPrazoEntrega();

    $sedex = $s->getValor();
    $prazoSedex = $s->getPrazoEntrega();

    $retorno = array("pac"=>$pac, "prazoP"=>$prazoPac, "sedex"=>$sedex, "prazoS"=>$prazoSedex);

    echo json_encode($retorno);
  }else{
    header("location:../");
  }

ajax code

$.ajax({
                  url: 'Controller/consultaCep.php',
                  type: 'POST',
                  data: dado,

                  success: function(r){
                    valorP = r.pac;
                    valorS = r.sedex;
                    prazoP = r.prazoP;
                    prazoS = r.prazoS;

                    alert(valorP);

                  $("#pacCorreio").val(valorP);
                  $("#pacCorreio").html("PAC - "+prazoP+" dias após postagem R$ "+valorP);
                  $("#sedexCorreio").val(valorS);
                  $("#sedexCorreio").html("Sedex - "+prazoS+" dias após postagem R$ "+valorS);
                  $("#todo").show();
                  }
                })

              });
    
asked by anonymous 13.11.2017 / 01:47

0 answers