What to put in the variable $ .post ajax

3

Hi, I'm not very good at javascript, ajax, jquery and json I'm still learning and remembering that I already researched a lot, but could not do what I want. It is the following my project is in MVC with friendly url. On the page has a text box that validates the zip and displays the values of the freight I did with PHP, but I had to put two radio options to choose the type of freight, I wanted the moment I clicked on the type of freight for example "pac" or "sedex" it would refresh the page and send that value to a PHP variable.

here is the file load.js.

$(document).ready(function() {
    $('#botao').click(function(){
        $('#aguarde, #blanket').css('display','block');
    });

  $("input:radio").click(function() {    

  var cor = $(this).val();

    var correio = cor;

     $.post("lojavirtualpoo/carrinho<-não estou sabendo colocar isso aqui",
    {
        correio: correio
    },function(){
        console.log(correio);
    });


 }); 


});

This page is located in localhost / lojavirtualpoo / app / views / cart / Index.php, inside the Index.php page has these code to receive the value but does not receive localhost / lojavirtualpoo / app / views / cart / Index.php

$tipo_correio = $_POST["correio"];
var_dump($tipo_correio);

html code on the same page

<td>

 <span class="tt1">Opção</span>

 <?php if ($cep_destino != "") { ?>

 <span class="tt2"><input type="radio" name="correio" value="pac"> 1</span>

 <span class="tt2"><input type="radio" name="correio" value="sedex"> 2</span>

 <?php } else { ?>

 <span class="tt2">Nenhum resultado</span>

 <?php } ?>

</td>

Here's an image for you to better understand what I want

    
asked by anonymous 25.11.2018 / 16:58

1 answer

0

Carlos, it was a bit confusing the question, but I made this flow ...

$(document).ready(function() {
    $('#botao').click(function(){
        $('#aguarde, #blanket').css('display','block');
    });

  $("input:radio").click(function() {  
    let cor = $(this).val();
    let correio = cor;
	
    let tipoFrete = ''; // id ou string com tipo de frete

    $.ajax({
	method: 'POST',
	url: 'rota de busca do cep',
	data: {frete: tipoFrete},
	dataType: 'JSON',
	})
	.done(function (response) {
	  // executa alguma ação após a ação no servidor for efetivada com sucesso
	})
	.fail(function(error) {
	  console.error(error)
	})

   }); 


});
    
26.11.2018 / 18:08